"use strict";

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

var _default = definition => {
  const result = [];

  const addDimension = (category, options) => {
    const values = ['default', ...options];

    if (!result.length) {
      result.push(...values.map(value => ({
        [category]: value
      })));
      return;
    }

    values.forEach((value, i) => {
      if (i === 0) {
        result.forEach(item => {
          item[category] = value;
        });
      } else {
        const copy = JSON.parse(JSON.stringify(result));
        copy.forEach(item => {
          item[category] = value;
        });
        result.push(...copy);
      }
    });
  };

  Object.keys(definition).forEach(key => {
    addDimension(key, definition[key]);
  }); // remove defaults

  const propVariants = result.map(item => {
    const props = {};
    Object.keys(item).forEach(key => {
      const value = item[key];

      if (value !== 'default') {
        props[value] = true;
      }
    });
    return props;
  });
  const results = {};
  propVariants.forEach(props => {
    results[Object.keys(props).sort().join(',')] = true;
  });
  const deduped = Object.keys(results).map(key => key.split(','));
  return deduped.map(propArray => {
    return propArray.reduce((result, item) => {
      if (item) {
        result[item] = true;
      }

      return result;
    }, {});
  });
};

exports.default = _default;