import _ from "lodash";
/**
 * A class implementing the all mode for multi articles.
 * This is a mode where the user is shown all available properties and values at once.
 * Note that this does not exclude invalid configurations, i.e. the user can set values such that no article matches the config.
 */
var AllMode = /** @class */ (function () {
    /**
     * The constructor.
     * @param multiArticles
     * @param start: the entry point for the all mode
     */
    function AllMode(multiArticles, start) {
        this.multiArticles = multiArticles;
        this.startConfiguration = this.multiArticles.getConfiguration(start);
        this._root = this.multiArticles.getRootAncestor(start);
        this.rootDescendants = this.multiArticles.getDescendants(this._root);
    }
    Object.defineProperty(AllMode.prototype, "root", {
        get: function () {
            return this._root;
        },
        set: function (newRoot) {
            this._root = newRoot;
            this.rootDescendants = this.multiArticles.getDescendants(this._root);
        },
        enumerable: true,
        configurable: true
    });
    /**
     * Get all available properties of all descendants. Also add the properties of the root MA.
     * @param configuration
     * @returns {T[]}
     */
    AllMode.prototype.getProperties = function (configuration) {
        var _this = this;
        var descendantProperties = _.flatMap(this.rootDescendants, function (article) {
            return _this.multiArticles.accumulatedProperties(article);
        });
        var rootProperties = this.multiArticles.accumulatedProperties(this._root);
        return _.uniq(descendantProperties.concat(_.keys(this.startConfiguration)));
    };
    /**
     * Get the available values for a property. Includes the roots values as well as the descendant values.
     * @param property
     * @param configuration
     * @returns {T[]}
     */
    AllMode.prototype.getPropertyValues = function (property, configuration) {
        var _this = this;
        var rootValues = this.multiArticles.getPropertyValues(this._root, property);
        var descendantValues = _.flatMap(this.rootDescendants, function (article) {
            return _this.multiArticles.getPropertyValues(article, property);
        });
        return _.uniq(_.compact(rootValues.concat(descendantValues)));
    };
    return AllMode;
}());
export default AllMode;
