const production = {
  presets: [['@babel/preset-env', { exclude: ['transform-classes'] }], '@babel/preset-flow', '@babel/preset-react'],
  plugins: [
    'babel-plugin-closure-elimination',
    [
      'babel-plugin-transform-react-remove-prop-types',
      {
        removeImport: true,
      },
    ],
  ],
}

const test = (module.exports.test = {
  presets: ['@babel/preset-react', ['@babel/preset-env'], '@babel/preset-flow'],
  plugins: [
    [
      '@babel/plugin-proposal-decorators',
      {
        legacy: true,
      },
    ],
    [
      '@babel/plugin-proposal-class-properties',
      {
        loose: true,
      },
    ],
    '@babel/plugin-proposal-throw-expressions',
    '@babel/plugin-proposal-object-rest-spread',
    '@babel/plugin-proposal-optional-chaining',
    '@babel/plugin-proposal-optional-catch-binding',
    'babel-plugin-jsx-control-statements',
    '@babel/plugin-proposal-export-default-from',
    [
      '@babel/plugin-transform-react-jsx',
      {
        pragma: 'React.createElement',
        pragmaFrag: 'React.Fragment',
      },
    ],
    [
      'babel-plugin-module-resolver',
      {
        cwd: 'packagejson',
        alias: {
          '^#components/(.+)': './src/new_components/\\1',
          '^#utilities/(.+)': './src/utilities/\\1',
          '^#types/(.+)': './src/types/\\1',
        },
      },
    ],
  ],
})

module.exports = {
  env: {
    test,
    production,
  },

  presets: [['@babel/preset-env'], '@babel/preset-flow', '@babel/preset-react'],

  plugins: [
    '@babel/plugin-syntax-dynamic-import',
    [
      '@babel/plugin-proposal-decorators',
      {
        legacy: true,
      },
    ],
    [
      '@babel/plugin-proposal-class-properties',
      {
        loose: true,
      },
    ],
    '@babel/plugin-proposal-throw-expressions',
    '@babel/plugin-proposal-object-rest-spread',
    '@babel/plugin-proposal-optional-catch-binding',
    '@babel/plugin-proposal-optional-chaining',
    'babel-plugin-jsx-control-statements',
    '@babel/plugin-proposal-export-default-from',
    [
      '@babel/plugin-transform-react-jsx',
      {
        pragma: 'React.createElement',
        pragmaFrag: 'React.Fragment',
      },
    ],
    [
      'babel-plugin-transform-react-remove-prop-types',
      {
        removeImport: true,
      },
    ],
    [
      'babel-plugin-module-resolver',
      {
        root: ['./'],
        cwd: 'babelrc',
        alias: {
          '^examples/(.+)': './examples\\1',
          '^components/(.+)': './src/components/\\1',
          '^#components/(.+)': './src/new_components/\\1',
          '^#utilities/(.+)': './src/utilities/\\1',
          '^#types/(.+)': './src/types/\\1',
        },
      },
    ],
    [
      'babel-plugin-react-css-modules',
      {
        generateScopedName: '__[name]-[local]',
        handleMissingStyleName: 'warn',
        webpackHotModuleReloading: true,
        context: '.${PWD}/packages/core/src',
        exclude: 'node_modules',
        attributeNames: {
          styleName: 'className',
        },
      },
    ],
    [
      '@babel/plugin-transform-runtime',
      {
        helpers: false,
        regenerator: true,
      },
    ],
  ],
}
