text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.validateOptions = exports.OptionsSchema = exports.DEFAULT_OPTIONS = void 0;
  const tslib_1 = require("tslib");
  const utils_validation_1 = require("@docusaurus/utils-validation");
  const utils_1 = require("@docusaurus/utils");
  const chalk_1 = tslib_1.__importDefault(require("chalk"));
  const remark_admonitions_1 = tslib_1.__importDefault(require("remark-admonitions"));
  const sidebarItemsGenerator_1 = require("./sidebarItemsGenerator");
  const numberPrefix_1 = require("./numberPrefix");
  exports.DEFAULT_OPTIONS = {
      path: 'docs',
      routeBasePath: 'docs',
      homePageId: undefined,
      include: ['**/*.{md,mdx}'],
      exclude: utils_1.GlobExcludeDefault,
      sidebarItemsGenerator: sidebarItemsGenerator_1.DefaultSidebarItemsGenerator,
      numberPrefixParser: numberPrefix_1.DefaultNumberPrefixParser,
      docLayoutComponent: '@theme/DocPage',
      docItemComponent: '@theme/DocItem',
      docTagDocListComponent: '@theme/DocTagDocListPage',
      docTagsListComponent: '@theme/DocTagsListPage',
      remarkPlugins: [],
      rehypePlugins: [],
      beforeDefaultRemarkPlugins: [],
      beforeDefaultRehypePlugins: [],
      showLastUpdateTime: false,
      showLastUpdateAuthor: false,
      admonitions: {},
      includeCurrentVersion: true,
      disableVersioning: false,
      lastVersion: undefined,
      versions: {},
      editCurrentVersion: false,
      editLocalizedFiles: false,
      sidebarCollapsible: true,
      sidebarCollapsed: true,
  };
  const VersionOptionsSchema = utils_validation_1.Joi.object({
      path: utils_validation_1.Joi.string().allow('').optional(),
      label: utils_validation_1.Joi.string().optional(),
      banner: utils_validation_1.Joi.string().equal('none', 'unreleased', 'unmaintained').optional(),
      badge: utils_validation_1.Joi.boolean().optional(),
      className: utils_validation_1.Joi.string().optional(),
  });
  const VersionsOptionsSchema = utils_validation_1.Joi.object()
      .pattern(utils_validation_1.Joi.string().required(), VersionOptionsSchema)
      .default(exports.DEFAULT_OPTIONS.versions);
  exports.OptionsSchema = utils_validation_1.Joi.object({
      path: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.path),
      editUrl: utils_validation_1.Joi.alternatives().try(utils_validation_1.URISchema, utils_validation_1.Joi.function()),
      editCurrentVersion: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.editCurrentVersion),
      editLocalizedFiles: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.editLocalizedFiles),
      routeBasePath: utils_validation_1.Joi.string()
          // '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
          // .allow('') ""
          .default(exports.DEFAULT_OPTIONS.routeBasePath),
      homePageId: utils_validation_1.Joi.string().optional(),
      include: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.include),
      exclude: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string()).default(exports.DEFAULT_OPTIONS.exclude),
      sidebarPath: utils_validation_1.Joi.alternatives().try(utils_validation_1.Joi.boolean().invalid(true), utils_validation_1.Joi.string()),
      sidebarItemsGenerator: utils_validation_1.Joi.function().default(() => exports.DEFAULT_OPTIONS.sidebarItemsGenerator),
      sidebarCollapsible: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.sidebarCollapsible),
      sidebarCollapsed: utils_validation_1.Joi.boolean().default(exports.DEFAULT_OPTIONS.sidebarCollapsed),
      numberPrefixParser: utils_validation_1.Joi.alternatives()
          .try(utils_validation_1.Joi.function(), 
      // Convert boolean values to functions
      utils_validation_1.Joi.alternatives().conditional(utils_validation_1.Joi.boolean(), {
          then: utils_validation_1.Joi.custom((val) => val ? numberPrefix_1.DefaultNumberPrefixParser : numberPrefix_1.DisabledNumberPrefixParser),
      }))
          .default(() => exports.DEFAULT_OPTIONS.numberPrefixParser),
      docLayoutComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docLayoutComponent),
      docItemComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docItemComponent),
      docTagsListComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docTagsListComponent),
      docTagDocListComponent: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.docTagDocListComponent),
      remarkPlugins: utils_validation_1.RemarkPluginsSchema.default(exports.DEFAULT_OPTIONS.remarkPlugins),
      rehypePlugins: utils_validation_1.RehypePluginsSchema.default(exports.DEFAULT_OPTIONS.rehypePlugins),
      beforeDefaultRemarkPlugins: utils_validation_1.RemarkPluginsSchema.default(exports.DEFAULT_OPTIONS.beforeDefaultRemarkPlugins),
      beforeDefaultRehypePlugins: utils_validation_1.RehypePluginsSchema.default(exports.DEFAULT_OPTIONS.beforeDefaultRehypePlugins),
      admonitions: utils_validation_1.Joi.alternatives()
          .try(utils_validation_1.AdmonitionsSchema, utils_validation_1.Joi.boolean().invalid(true))
          .default(exports.DEFAULT_OPTIONS.admonitions),
      showLastUpdateTime: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.showLastUpdateTime),
      showLastUpdateAuthor: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.showLastUpdateAuthor),
      includeCurrentVersion: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.includeCurrentVersion),
      onlyIncludeVersions: utils_validation_1.Joi.array().items(utils_validation_1.Joi.string().required()).optional(),
      disableVersioning: utils_validation_1.Joi.bool().default(exports.DEFAULT_OPTIONS.disableVersioning),
      lastVersion: utils_validation_1.Joi.string().optional(),
      versions: VersionsOptionsSchema,
  });
  function validateOptions({ validate, options: userOptions, }) {
      let options = userOptions;
      if (options.sidebarCollapsible === false) {
          // When sidebarCollapsible=false and sidebarCollapsed=undefined, we don't want to have the inconsistency warning
          // We let options.sidebarCollapsible become the default value for options.sidebarCollapsed
          if (typeof options.sidebarCollapsed === 'undefined') {
              options = {
                  ...options,
                  sidebarCollapsed: false,
              };
          }
          if (options.sidebarCollapsed) {
              console.warn(chalk_1.default.yellow('The docs plugin config is inconsistent. It does not make sense to use sidebarCollapsible=false and sidebarCollapsed=true at the same time. sidebarCollapsed=false will be ignored.'));
              options = {
                  ...options,
                  sidebarCollapsed: false,
              };
          }
      }
      // TODO remove homePageId before end of 2020
      // "slug: /" is better because the home doc can be different across versions
      if (options.homePageId) {
          console.log(chalk_1.default.red(`The docs plugin option homePageId=${options.homePageId} is deprecated. To make a doc the "home", prefer frontmatter: "slug: /"`));
      }
      const normalizedOptions = validate(exports.OptionsSchema, options);
      if (normalizedOptions.admonitions) {
          normalizedOptions.remarkPlugins = normalizedOptions.remarkPlugins.concat([
              [remark_admonitions_1.default, normalizedOptions.admonitions],
          ]);
      }
      return normalizedOptions;
  }
  exports.validateOptions = validateOptions;
  