const env = process.env.NODE_ENV;
const pkg = require('./package.json');
const path = require('path');

const isDevEnv = env === 'development';
const { webpack: webpackConfig } = require('./webpack.config.js');

webpackConfig.module.rules.push({
  test: /\.css$/,
  use: ['style-loader', 'css-loader'],
});

module.exports = {
  styleguideDir: 'docs',

  title: 'ReadMe UI',
  pagePerSection: true,

  usageMode: isDevEnv ? 'expand' : 'collapse',
  exampleMode: 'collapse',
  template: {
    head: {
      links: [
        {
          rel: 'stylesheet',
          href: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css',
        },
      ],
    },
  },
  sections: [
    { name: 'ReadMe UI', content: 'docs/src/home.md', sectionDepth: 0 },
    {
      name: 'Overview',
      content: 'readme.md',
      sectionDepth: 1,
      sections: [
        {
          name: 'Usage',
          content: 'docs/src/usage/index.md',
          sections: [
            { name: 'Getting Started', content: 'docs/src/usage/getting-started.md' },
            { name: 'Usage in ReadMe', content: 'docs/src/usage/directive.md' },
            { name: 'Custom Hooks', content: 'docs/src/usage/custom-hooks.md' },
          ],
        },
        {
          name: 'Contributing',
          content: 'docs/src/contributing/index.md',
          sectionDepth: 0,
          sections: [
            { name: 'Code Conventions', content: 'docs/src/contributing/coding.md' },
            { name: 'Pull Requests', content: 'docs/src/contributing/git-prs.md' },
          ],
        },
        /* {
          name: 'Quick Composer',
          exampleMode: 'expand',
          content: 'docs/src/quick-composer.md',
        }, */
      ],
    },
    {
      name: 'Design System',
      content: 'src/styles/readme.md',
      sections: [
        // { name: 'Aesthetics', content: 'docs/src/styles/principles.md' },
        { name: 'Design Tokens', content: 'src/styles/tokens/readme.md' },
        { name: 'Methods', content: 'src/styles/methods/readme.md' },
        { name: 'Mixins', content: 'src/styles/mixins/readme.md' },
        { name: 'Class Conventions', content: 'docs/src/styles/bem.md' },
      ],
    },
    {
      name: 'UI Library',
      content: 'src/ui/readme.md',
      sectionDepth: 1,
      sections: [
        {
          name: 'Components',
          content: 'src/ui/components/readme.md',
          components: ['src/ui/components/**/index.{js,jsx}'],
          ignore: ['src/ui/components/index.js'],
        },
        {
          name: 'Compositions',
          content: 'src/ui/compositions/readme.md',
          components: ['src/ui/compositions/*/index.{js,jsx}'],
          ignore: ['src/ui/compositions/index.js'],
          sections: [
            {
              name: 'Tutorials',
              components: ['src/ui/compositions/Tutorials/*/index.{js,jsx}'],
            },
            {
              name: 'Staging',
              components: ['src/ui/compositions/Staging/*/index.{js,jsx}'],
            },
          ],
        },
        {
          name: 'Views',
          components: ['src/views/*/index.{js,jsx}'],
          ignore: ['src/views/index.js'],
        },
        isDevEnv
          ? {
              name: 'Marketing',
              components: ['src/ui/marketing/*/index.{js,jsx}'],
              ignore: ['src/ui/marketing/index.js'],
            }
          : {},
      ],
    },
    isDevEnv
      ? {
          name: 'Repository',
          href: pkg.repository.url.split('git+').join(''),
        }
      : {
          name: 'NPM Registry',
          href: `https://www.npmjs.com/package/${pkg.name}`,
        },
  ],
  require: [
    path.join(__dirname, 'docs/lib/style.css'),
    path.join(__dirname, 'docs/lib/toggle-props.css'),
    path.join(__dirname, 'src/styles/main.scss'),
    path.join(__dirname, 'docs/lib/nav-toggling.js'),
  ],

  webpackConfig,
};
