"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CmatchVisibility = void 0;
/**
 * Expose visibility data from the client
 */
var CmatchVisibility = /** @class */ (function () {
    /**
     * @param _client - active client
     */
    function CmatchVisibility(_client) {
        this._client = _client;
    }
    /**
     * Get index visibility for classification names
     *
     * @param list - a list of classification/visibility names
     *
     * @return data containing the classfication name and visibility of indexes
     */
    CmatchVisibility.prototype.getBlueprints = function (list) {
        var _this = this;
        var classifications = this._client.getQuote().getLastClassify();
        return list.map(function (legend) {
            var vis_class_data = classifications[legend.cname];
            var output = __assign(__assign({}, legend), _this._getVisibilityShell());
            // Undefined
            if (!vis_class_data || vis_class_data.indexes === undefined) {
                return output;
                // Scalars
            }
            else if (typeof vis_class_data.indexes === 'number') {
                var action = vis_class_data.indexes === 1 ? 'show' : 'hide';
                output[action].push(0);
                // Vectors & Matrices
            }
            else if (Array.isArray(vis_class_data.indexes)) {
                var vis = _this._processArray(vis_class_data.indexes);
                vis.show.forEach(function (index) { return output.show.push(index); });
                vis.hide.forEach(function (index) { return output.hide.push(index); });
            }
            return output;
        });
    };
    /**
     * Get visibility info for array-based visibility
     *
     * @param indexes - array of visibilty data
     *
     * @return index visibility grouped by show and hide
     */
    CmatchVisibility.prototype._processArray = function (indexes) {
        var vis = this._getVisibilityShell();
        indexes.forEach(function (value, i) {
            var show = Array.isArray(value)
                ? value.some(function (v) { return +v === 1; })
                : +value === 1;
            var action = show ? 'show' : 'hide';
            vis[action].push(+i);
        });
        return vis;
    };
    /**
     * Get an empty shell to store visibility info
     *
     * @return empty shell of visibility info
     */
    CmatchVisibility.prototype._getVisibilityShell = function () {
        return {
            show: [],
            hide: [],
        };
    };
    return CmatchVisibility;
}());
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