import { __awaiter, __decorate, __generator, __values } from "tslib";
import { Pipe } from '@angular/core';
var CommandHidden = /** @class */ (function () {
    function CommandHidden() {
    }
    CommandHidden.prototype.transform = function (item, command) {
        return __awaiter(this, void 0, void 0, function () {
            var hidden, hiddenByItem, hiddenResult, results, _a, _b, childCommand, childHidden, childHiddenByItem, hiddenResult, e_1_1;
            var e_1, _c;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        hidden = command.hidden, hiddenByItem = command.hiddenByItem;
                        if (hidden) {
                            return [2 /*return*/, true];
                        }
                        if (!hiddenByItem) return [3 /*break*/, 3];
                        hiddenResult = hiddenByItem(item);
                        if (!(hiddenResult instanceof Promise)) return [3 /*break*/, 2];
                        return [4 /*yield*/, hiddenResult];
                    case 1:
                        if (_d.sent()) {
                            return [2 /*return*/, true];
                        }
                        return [3 /*break*/, 3];
                    case 2:
                        if (hiddenResult) {
                            return [2 /*return*/, true];
                        }
                        _d.label = 3;
                    case 3:
                        if (!('children' in command)) return [3 /*break*/, 14];
                        results = [];
                        _d.label = 4;
                    case 4:
                        _d.trys.push([4, 11, 12, 13]);
                        _a = __values(command.children), _b = _a.next();
                        _d.label = 5;
                    case 5:
                        if (!!_b.done) return [3 /*break*/, 10];
                        childCommand = _b.value;
                        childHidden = childCommand.hidden, childHiddenByItem = childCommand.hiddenByItem;
                        if (!(!childHidden && !childHiddenByItem)) return [3 /*break*/, 6];
                        results.push(childCommand);
                        return [3 /*break*/, 9];
                    case 6:
                        if (!childHiddenByItem) return [3 /*break*/, 9];
                        hiddenResult = childHiddenByItem(item);
                        if (!(hiddenResult instanceof Promise)) return [3 /*break*/, 8];
                        return [4 /*yield*/, hiddenResult];
                    case 7:
                        if (!(_d.sent())) {
                            results.push(childCommand);
                        }
                        return [3 /*break*/, 9];
                    case 8:
                        if (!hiddenResult) {
                            results.push(childCommand);
                        }
                        _d.label = 9;
                    case 9:
                        _b = _a.next();
                        return [3 /*break*/, 5];
                    case 10: return [3 /*break*/, 13];
                    case 11:
                        e_1_1 = _d.sent();
                        e_1 = { error: e_1_1 };
                        return [3 /*break*/, 13];
                    case 12:
                        try {
                            if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                        }
                        finally { if (e_1) throw e_1.error; }
                        return [7 /*endfinally*/];
                    case 13:
                        if (results.length === 0) {
                            return [2 /*return*/, true];
                        }
                        _d.label = 14;
                    case 14: return [2 /*return*/, false];
                }
            });
        });
    };
    CommandHidden = __decorate([
        Pipe({
            name: 'commandHidden'
        })
    ], CommandHidden);
    return CommandHidden;
}());
export { CommandHidden };
//# sourceMappingURL=data:application/json;base64, 