import { __awaiter, __decorate, __generator, __values } from "tslib";
import { Pipe } from '@angular/core';
var MobileCommandFilterPipe = /** @class */ (function () {
    function MobileCommandFilterPipe() {
    }
    MobileCommandFilterPipe.prototype.transform = function (commands, item) {
        return __awaiter(this, void 0, void 0, function () {
            var results, commands_1, commands_1_1, command, flag, hiddenByItem, hidden, _a, _b, childCommand, hidden, e_1_1, hiddenByItem, hidden, e_2_1;
            var e_2, _c, e_1, _d;
            return __generator(this, function (_e) {
                switch (_e.label) {
                    case 0:
                        results = [];
                        if (!commands) {
                            return [2 /*return*/, results];
                        }
                        _e.label = 1;
                    case 1:
                        _e.trys.push([1, 22, 23, 24]);
                        commands_1 = __values(commands), commands_1_1 = commands_1.next();
                        _e.label = 2;
                    case 2:
                        if (!!commands_1_1.done) return [3 /*break*/, 21];
                        command = commands_1_1.value;
                        if (!('children' in command)) return [3 /*break*/, 16];
                        flag = true;
                        hiddenByItem = command.hiddenByItem;
                        if (!hiddenByItem) return [3 /*break*/, 5];
                        hidden = hiddenByItem(item);
                        if (!(hidden instanceof Promise)) return [3 /*break*/, 4];
                        return [4 /*yield*/, hidden];
                    case 3:
                        if (_e.sent()) {
                            flag = false;
                        }
                        return [3 /*break*/, 5];
                    case 4:
                        if (hidden) {
                            flag = false;
                        }
                        _e.label = 5;
                    case 5:
                        if (!flag) return [3 /*break*/, 15];
                        _e.label = 6;
                    case 6:
                        _e.trys.push([6, 13, 14, 15]);
                        _a = (e_1 = void 0, __values(command.children)), _b = _a.next();
                        _e.label = 7;
                    case 7:
                        if (!!_b.done) return [3 /*break*/, 12];
                        childCommand = _b.value;
                        if (!!childCommand.hiddenByItem) return [3 /*break*/, 8];
                        results.push(childCommand);
                        return [3 /*break*/, 11];
                    case 8:
                        hidden = childCommand.hiddenByItem(item);
                        if (!(hidden instanceof Promise)) return [3 /*break*/, 10];
                        return [4 /*yield*/, hidden];
                    case 9:
                        if (!(_e.sent())) {
                            results.push(childCommand);
                        }
                        return [3 /*break*/, 11];
                    case 10:
                        if (!hidden) {
                            results.push(childCommand);
                        }
                        _e.label = 11;
                    case 11:
                        _b = _a.next();
                        return [3 /*break*/, 7];
                    case 12: return [3 /*break*/, 15];
                    case 13:
                        e_1_1 = _e.sent();
                        e_1 = { error: e_1_1 };
                        return [3 /*break*/, 15];
                    case 14:
                        try {
                            if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
                        }
                        finally { if (e_1) throw e_1.error; }
                        return [7 /*endfinally*/];
                    case 15: return [3 /*break*/, 20];
                    case 16:
                        hiddenByItem = command.hiddenByItem;
                        if (!!hiddenByItem) return [3 /*break*/, 17];
                        results.push(command);
                        return [3 /*break*/, 20];
                    case 17:
                        hidden = hiddenByItem(item);
                        if (!(hidden instanceof Promise)) return [3 /*break*/, 19];
                        return [4 /*yield*/, hidden];
                    case 18:
                        if (!(_e.sent())) {
                            results.push(command);
                        }
                        return [3 /*break*/, 20];
                    case 19:
                        if (!hidden) {
                            results.push(command);
                        }
                        _e.label = 20;
                    case 20:
                        commands_1_1 = commands_1.next();
                        return [3 /*break*/, 2];
                    case 21: return [3 /*break*/, 24];
                    case 22:
                        e_2_1 = _e.sent();
                        e_2 = { error: e_2_1 };
                        return [3 /*break*/, 24];
                    case 23:
                        try {
                            if (commands_1_1 && !commands_1_1.done && (_c = commands_1.return)) _c.call(commands_1);
                        }
                        finally { if (e_2) throw e_2.error; }
                        return [7 /*endfinally*/];
                    case 24: return [2 /*return*/, results];
                }
            });
        });
    };
    MobileCommandFilterPipe = __decorate([
        Pipe({
            name: 'mobileCommandFilter'
        })
    ], MobileCommandFilterPipe);
    return MobileCommandFilterPipe;
}());
export { MobileCommandFilterPipe };
//# sourceMappingURL=data:application/json;base64, 