const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  entry: {
    main: [
      path.resolve(__dirname, 'static/js/app.js'),
      path.resolve(__dirname, 'static/css/main.css'),
      path.resolve(__dirname, 'static/css/components/button.css'),
      path.resolve(__dirname, 'static/css/components/card.css'),
      path.resolve(__dirname, 'static/css/components/dialog.css'),
      path.resolve(__dirname, 'static/css/components/form.css'),
      path.resolve(__dirname, 'static/css/components/image.css'),
      path.resolve(__dirname, 'static/css/components/label.css'),
      path.resolve(__dirname, 'static/css/components/modal.css'),
      path.resolve(__dirname, 'static/css/components/navigation.css'),
      path.resolve(__dirname, 'static/css/components/overlay.css'),
      path.resolve(__dirname, 'static/css/components/table.css'),
      path.resolve(__dirname, 'static/css/layouts/header.css'),
      path.resolve(__dirname, 'static/css/layouts/footer.css'),
      path.resolve(__dirname, 'static/css/layouts/table-main.css'),
      path.resolve(__dirname, 'static/css/lib/reset.css'),
      path.resolve(__dirname, 'static/css/lib/typography.css'),
      path.resolve(__dirname, 'static/css/lib/utils.css'),
      path.resolve(__dirname, 'static/css/lib/variables.css'),
      path.resolve(__dirname, 'static/css/themes/dark.css'),
      // ...glob.sync(path.resolve(__dirname, 'static/css/main/**       /*.css')) // Include CSS files for the main page
    ],
    // Core
    // Legal
    /*
    legal_accessibility_report: [
      path.resolve(__dirname, 'static/js/pages/legal/accessibility_report.js'),
      path.resolve(__dirname, 'static/css/sections/core.css'),
      path.resolve(__dirname, 'static/css/pages/legal/accessibility_report.css')
    ],
    */
    legal_accessibility_statement: [
      path.resolve(__dirname, 'static/css/sections/legal.css'),
      path.resolve(__dirname, 'static/css/pages/legal/accessibility_statement.css')
    ],
    legal_retention_schedule: [
      path.resolve(__dirname, 'static/css/sections/legal.css'),
      path.resolve(__dirname, 'static/css/pages/legal/retention_schedule.css')
    ],
    legal_license: [
      path.resolve(__dirname, 'static/css/sections/legal.css'),
      path.resolve(__dirname, 'static/css/pages/legal/license.css')
    ],
    legal_privacy_policy: [
      path.resolve(__dirname, 'static/css/sections/legal.css'),
      path.resolve(__dirname, 'static/css/pages/legal/privacy_policy.css')
    ],
    // TCG
    tcg_decks: [
      path.resolve(__dirname, 'static/css/sections/tcg.css'),
      path.resolve(__dirname, 'static/css/pages/tcg/decks.css')
    ],
    tcg_game: [
      path.resolve(__dirname, 'static/css/sections/tcg.css'),
      path.resolve(__dirname, 'static/css/pages/tcg/game.css')
    ],
    tcg_games: [
      path.resolve(__dirname, 'static/css/sections/tcg.css'),
      path.resolve(__dirname, 'static/css/pages/tcg/games.css')
    ],
    tcg_home: [
      path.resolve(__dirname, 'static/css/sections/tcg.css'),
      path.resolve(__dirname, 'static/css/pages/tcg/home.css')
    ],
    // User
    user_account: [
        path.resolve(__dirname, 'static/css/sections/tcg.css'),
        path.resolve(__dirname, 'static/css/sections/user.css'),
        path.resolve(__dirname, 'static/css/pages/user/user.css')
    ],
    user_accounts: [
        path.resolve(__dirname, 'static/css/sections/user.css'),
        path.resolve(__dirname, 'static/css/sections/tcg.css'),
        path.resolve(__dirname, 'static/css/pages/user/users.css')
    ],
  },
  output: {
    filename: 'js/[name].bundle.js',
    path: path.resolve(__dirname, 'static/dist'),
    chunkFilename: '[name].chunk.js', // Non-entry chunk filename
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
        ],
      },
      {
          test: /\.js$/,
          exclude: path.resolve(__dirname, 'templates'), // Exclude templates folder
          use: {
              loader: 'babel-loader',
          },
      },
    ],
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'css/[name].bundle.css',
    }),
  ],
  resolve: {
    extensions: ['.js', '.json', '.wasm']
  },
  optimization: {
    splitChunks: {
      chunks: 'all'
    },
    minimize: false,
  },
  mode: 'development',
  devtool: 'source-map',
};