text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const request_1 = require("../../../../request");
  const commands_1 = require("../../commands");
  const SpoCommand_1 = require("../../../base/SpoCommand");
  const vorpal = require('../../../../vorpal-init');
  class SpoHubSiteDisconnectCommand extends SpoCommand_1.default {
      get name() {
          return `${commands_1.default.HUBSITE_DISCONNECT}`;
      }
      get description() {
          return 'Disconnects the specifies site collection from its hub site';
      }
      getTelemetryProperties(args) {
          const telemetryProps = super.getTelemetryProperties(args);
          telemetryProps.confirm = args.options.confirm || false;
          return telemetryProps;
      }
      commandAction(cmd, args, cb) {
          const disconnectHubSite = () => {
              this
                  .getRequestDigest(args.options.url)
                  .then((res) => {
                  if (this.verbose) {
                      cmd.log(`Disconnecting site collection ${args.options.url} from its hubsite...`);
                  }
                  const requestOptions = {
                      url: `${args.options.url}/_api/site/JoinHubSite('00000000-0000-0000-0000-000000000000')`,
                      headers: {
                          'X-RequestDigest': res.FormDigestValue,
                          accept: 'application/json;odata=nometadata'
                      },
                      json: true
                  };
                  return request_1.default.post(requestOptions);
              })
                  .then(() => {
                  if (this.verbose) {
                      cmd.log(vorpal.chalk.green('DONE'));
                  }
                  cb();
              }, (err) => this.handleRejectedODataJsonPromise(err, cmd, cb));
          };
          if (args.options.confirm) {
              disconnectHubSite();
          }
          else {
              cmd.prompt({
                  type: 'confirm',
                  name: 'continue',
                  default: false,
                  message: `Are you sure you want to disconnect the site collection ${args.options.url} from its hub site?`,
              }, (result) => {
                  if (!result.continue) {
                      cb();
                  }
                  else {
                      disconnectHubSite();
                  }
              });
          }
      }
      options() {
          const options = [
              {
                  option: '-u, --url <url>',
                  description: 'URL of the site collection to disconnect from its hub site'
              },
              {
                  option: '--confirm',
                  description: 'Don\'t prompt for confirming disconnecting from the hub site'
              }
          ];
          const parentOptions = super.options();
          return options.concat(parentOptions);
      }
      validate() {
          return (args) => {
              if (!args.options.url) {
                  return 'Required parameter url missing';
              }
              const isValidSharePointUrl = SpoCommand_1.default.isValidSharePointUrl(args.options.url);
              if (isValidSharePointUrl !== true) {
                  return isValidSharePointUrl;
              }
              return true;
          };
      }
      commandHelp(args, log) {
          const chalk = vorpal.chalk;
          log(vorpal.find(this.name).helpInformation());
          log(`  Remarks:
  
      ${chalk.yellow('Attention:')} This command is based on a SharePoint API that is currently
      in preview and is subject to change once the API reached general
      availability.
  
    Examples:
    
      Disconnect the site collection with URL
      ${chalk.grey('https://contoso.sharepoint.com/sites/sales')} from its hub site. Will prompt
      for confirmation before disconnecting from the hub site.
        ${this.name} --url https://contoso.sharepoint.com/sites/sales
  
      Disconnect the site collection with URL
      ${chalk.grey('https://contoso.sharepoint.com/sites/sales')} from its hub site without
      prompting for confirmation
        ${this.name} --url https://contoso.sharepoint.com/sites/sales --confirm
  
    More information:
  
      SharePoint hub sites new in Office 365
        https://techcommunity.microsoft.com/t5/SharePoint-Blog/SharePoint-hub-sites-new-in-Office-365/ba-p/109547
  `);
      }
  }
  module.exports = new SpoHubSiteDisconnectCommand();
  //# sourceMappingURL=hubsite-disconnect.js.map