import { defineConfig } from 'dumi';
import { readdirSync } from 'fs';
import { join } from 'path';

const headPkgList: any = [];
// utils must build before core
// runtime must build before renderer-react
const pkgList = readdirSync(join(__dirname, 'components')).filter(
  (pkg) => pkg.charAt(0) !== '.' && !headPkgList.includes(pkg),
);

const tailPkgList = pkgList
  .map((path) => [join('components', path)])
  .reduce((acc, val) => acc.concat(val), []);

export default defineConfig({
  title: 'Fle-UI',
  mode: 'site',
  favicon:
    'https://oss.elebuys.com/resource/programme/202106211028580003961886.png',
  logo: 'https://oss.elebuys.com/resource/programme/202106211028580003961886.png',
  resolve: {
    includes: [...tailPkgList, 'docs'],
  },
  outputPath: 'docs-dist',
  alias: {
    '@fle-ui/next': join(__dirname, 'components'),
    '@fle-ui/next/es': join(__dirname, 'components'),
    '@fle-ui/next/lib': join(__dirname, 'components'),
  },
  define: {
    'process.env.BUILD_TYPE_CUS': 'docs',
  },
  dynamicImport: {},
  navs: [
    {
      title: '文档',
      path: '/document',
    },
    {
      title: '组件',
      path: '/components',
    },
    {
      title: '社区资源',
      children: [
        {
          title: 'fle-ui-pro 业务组件',
          path: 'https://fle-ui-pro.fxqifu.com/',
        },
        { title: 'fle-cli', path: 'https://flecli.fxqifu.com/' },
        { title: 'fle-git', path: 'https://flecli.fxqifu.com/fle-git' },
        { title: '常用工具', path: 'https://flecli.fxqifu.com/community/copy' },
      ],
    },
    {
      title: '发布记录',
      path: '/story',
    },
    {
      title: 'GitLab',
      path: 'https://gitlab.fxqifu.com.cn/fle-ui/fle-ui-next',
    },
  ],
  mfsu: {},
  menus: {
    '/components': [
      {
        title: '通用',
        children: ['button', 'icon', 'typography'],
      },
      {
        title: '布局',
        children: ['divider', 'grid', 'layout', 'space'],
      },
      {
        title: '导航',
        children: [
          'affix',
          'breadcrumb',
          'steps',
          'dropdown',
          'menu',
          'pagination',
          'page-header',
        ],
      },
      {
        title: '数据录入',
        children: [
          'autoComplete',
          'cascader',
          'checkbox',
          'date-picker',
          'form',
          'input',
          'inputNumber',
          'mentions',
          'radio',
          'select',
          'slider',
          'switch',
          'time-picker',
          'transfer',
          'tree-select',
          'upload',
          'rate',
        ],
      },
      {
        title: '数据展示',
        children: [
          'avatar',
          'badge',
          'calendar',
          'card',
          'carousel',
          'collapse',
          'comment',
          'descriptions',
          'empty',
          'image',
          'list',
          'statistic',
          'table',
          'tabs',
          'tag',
          'timeline',
          'tooltip',
          'popover',
          'tree',
        ],
      },
      {
        title: '反馈',
        children: [
          'alert',
          'drawer',
          'message',
          'modal',
          'notification',
          'popconfirm',
          'progress',
          'result',
          'skeleton',
          'spin',
        ],
      },
      {
        title: '其他',
        children: ['anchor', 'backTop', 'configProvider'],
      },
    ],
  },
});
