function _instanceof(left, right) {
    "@swc/helpers - instanceof";
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
import { merge } from "d3-array";
/**
    @module clickLegend
    On click event for all legend shapes in a Viz.
    @private
*/ export default function(d, i, x, event) {
    var _this = this;
    this._select.style("cursor", "auto");
    if (this._tooltip(d, i)) this._tooltipClass.data([]).render();
    var id = this._id(d, i);
    if (!_instanceof(id, Array)) id = [
        id
    ];
    var hiddenIndex = this._hidden.indexOf(id[0]);
    var soloIndex = this._solo.indexOf(id[0]);
    var dataLength = merge(this._legendClass.data().map(function(d, i) {
        var id = _this._id(d, i);
        if (!_instanceof(id, Array)) id = [
            id
        ];
        return id;
    })).length;
    var inverted = this._legendFilterInvert.bind(this)();
    if (inverted) {
        if (event.shiftKey) {
            if (hiddenIndex < 0 && !this._solo.length) {
                this._hidden = this._hidden.concat(id);
                if (soloIndex >= 0) this._solo = [];
                if (this._hidden.length === dataLength) this._hidden = [];
                this.render();
            } else if (soloIndex >= 0) {
                this._solo = [];
                this._hidden = [];
                this.render();
            }
        } else {
            if (soloIndex < 0 && this._hidden.length < dataLength - 1) {
                this._solo = id;
                this._hidden = [];
            } else {
                this._solo = [];
                this._hidden = [];
            }
            this.render();
        }
    } else {
        if (event.shiftKey && soloIndex < 0) {
            this._solo = id;
            this._hidden = [];
            this.render();
        } else if (!event.shiftKey) {
            if (hiddenIndex >= 0) {
                this._hidden.splice(hiddenIndex, id.length);
            } else if (soloIndex >= 0) {
                this._solo = [];
                this._hidden = [];
            } else if (this._solo.length && soloIndex < 0) {
                this._solo = this._solo.concat(id);
                if (this._solo.length === dataLength) this._solo = [];
            } else {
                this._hidden = this._hidden.concat(id);
                if (this._hidden.length === dataLength) this._hidden = [];
            }
            this.render();
        }
    }
}
