"use strict";

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

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

module.exports = _postcss.default.plugin('postcss-include-files', opts => {
  const {
    plugins
  } = opts;
  return (root, result) => {
    const inputFile = root.source.input.file;
    const includeFile = opts.include.some(file => inputFile.indexOf(file) !== -1);

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

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