"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
exports.excludeEmptyCheckPlugin = excludeEmptyCheckPlugin;

var _postcss = _interopRequireDefault(require("postcss"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const ExcludePlugin = opts => {
  const {
    plugins,
    exclude
  } = opts;
  return {
    postcssPlugin: 'postcss-dark-theme-class',

    Once(root, {
      result
    }) {
      const inputFile = root.source.input.file;
      const isIgnoredFile = exclude.some(file => inputFile.indexOf(file) !== -1);

      if (!isIgnoredFile) {
        const handler = response => response.messages.forEach(msg => result.messages.push(msg));

        return (0, _postcss.default)(plugins).process(root, {
          from: undefined
        }).then(handler);
      }

      return root;
    }

  };
};

ExcludePlugin.postcss = true;
var _default = ExcludePlugin;
exports.default = _default;

function excludeEmptyCheckPlugin({
  enable,
  exclude,
  plugins
}) {
  if (!enable) {
    return [];
  }

  return exclude.length === 0 ? plugins : [ExcludePlugin({
    exclude,
    plugins
  })];
}