import { defaultPalette } from '../js/getCustomTheme';
import Snippet from './Snippet';
export default new Map([['palette', {
  test: /^\.palette$/i,
  multiple: false,
  defaultValue: defaultPalette,
  defaultName: '.palette'
}], ['env', {
  test: /^\.env$/i,
  multiple: false,
  defaultValue: {
    MODULE: [true, 'boolean', 'A flag to use module bundler']
  },
  defaultName: '.env'
}], ['babelrc', {
  test: /^\.babelrc$/i,
  multiple: false,
  defaultValue: {
    presets: ['es2015']
  },
  defaultName: '.babelrc'
}], ['snippets', {
  test: /^snippets\/.*\.json$/i,
  multiple: true,
  defaultValue: {},
  defaultName: 'snippets/snippet.json',
  bundle: function bundle(files) {
    var snippets = files.reduce(function (p, file) {
      var definition = {};

      try {
        definition = JSON.parse(file.text);
      } catch (error) {
        console.warn('Invalid snippet', file.name, file.text);
        return p;
      }

      Object.keys(definition).forEach(function (scope) {
        p[scope] = (p[scope] || []).concat(Object.keys(definition[scope]).map(function (key) {
          return new Snippet(Object.assign({
            name: file.name
          }, definition[scope][key]));
        }));
      });
      return p;
    }, Object.create(null));
    var scopes = Object.keys(snippets);
    return function (file) {
      return scopes.filter(function (scope) {
        return file && file.is(scope);
      }).map(function (scope) {
        return snippets[scope];
      }).reduce(function (p, c) {
        return p.concat(c);
      }, []);
    };
  }
}]]);