const path = require('path');
const purgecss = require('@fullhuman/postcss-purgecss');

module.exports = () => {
    const env = process.env.NODE_ENV || 'development';
    const prod = env === 'production';

    const config = {
        plugins: [
            require('postcss-import'),
            require('tailwindcss')(process.env.TAILWIND_CONFIG || path.resolve(__dirname, 'tailwind.config.js')),
            require('autoprefixer'),
        ],
    };

    if (prod) {
        config.plugins.push(
            purgecss({
                content: [
                    './node_modules/@newland/**/*.vue',
                    './node_modules/v-calendar/src/**/*.vue',
                ],
                extractors: [
                    {
                        extractor: content => content.match(/[\w-/.:]+(?<!:)/g) || [],
                        extensions: [ 'scss', 'sass', 'css', 'vue', 'md' ],
                    },
                ],
                whitelistPatterns: [ /^redactor-/, /^re-/, /^mtk-/, /^gap-/, /^grid-cols-/, /^tb-/ ],
                whitelist: [ 'visually-hidden', 'sr-only', 'bg-alert', 'bg-gray-400' ],
            }),
        );
    }


    return config;
};
