import { __generator } from "tslib";
import { ensureBool } from "./componentUtil";
import { FilterExpressionCollection as FilterExpressionCollection_internal } from "./FilterExpressionCollection";
/**
 * Represents a colleciton of filter expressions.
*/
var IgrFilterExpressionCollection = /** @class */ /*@__PURE__*/ (function () {
    function IgrFilterExpressionCollection() {
        this._implementation = this.createImplementation();
        this._implementation.externalObject = this;
        this.onImplementationCreated();
    }
    IgrFilterExpressionCollection.prototype.createImplementation = function () {
        return new FilterExpressionCollection_internal();
    };
    Object.defineProperty(IgrFilterExpressionCollection.prototype, "i", {
        get: function () {
            return this._implementation;
        },
        enumerable: false,
        configurable: true
    });
    IgrFilterExpressionCollection.prototype.onImplementationCreated = function () {
    };
    IgrFilterExpressionCollection.prototype._provideImplementation = function (i) {
        this._implementation = i;
        this._implementation.externalObject = this;
        this.onImplementationCreated();
    };
    IgrFilterExpressionCollection.prototype.item = function (index, value) {
        var filter = null;
        if (value !== undefined) {
            filter = this.set(index, value == null ? null : value);
        }
        else {
            filter = this.get(index);
        }
        return filter;
    };
    Object.defineProperty(IgrFilterExpressionCollection.prototype, "count", {
        get: function () {
            return this.i.size();
        },
        enumerable: false,
        configurable: true
    });
    IgrFilterExpressionCollection.prototype.toArray = function () {
        var arr = [];
        for (var i = 0; i < this.count; i++) {
            arr[i] = this.item(i);
        }
        return arr;
    };
    IgrFilterExpressionCollection.prototype[Symbol.iterator] = function () {
        var i, item;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    i = 0;
                    _a.label = 1;
                case 1:
                    if (!(i < this.count))
                        return [3 /*break*/, 4];
                    item = this.item(i);
                    if (item.externalObject) {
                        item = item.externalObject;
                    }
                    return [4 /*yield*/, item];
                case 2:
                    _a.sent();
                    _a.label = 3;
                case 3:
                    i++;
                    return [3 /*break*/, 1];
                case 4: return [2 /*return*/];
            }
        });
    };
    Object.defineProperty(IgrFilterExpressionCollection.prototype, "syncTarget", {
        get: function () {
            var r = this.i.syncTarget;
            if (r == null) {
                return null;
            }
            if (!r.externalObject) {
                var e = new IgrFilterExpressionCollection();
                if (e.i.setNativeElement) {
                    e.i.setNativeElement(r);
                }
                else {
                    e._implementation = r;
                }
                r.externalObject = e;
            }
            return r.externalObject;
        },
        set: function (v) {
            v == null ? this.i.syncTarget = null : this.i.syncTarget = v.i;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(IgrFilterExpressionCollection.prototype, "shouldDetachOnTargetChange", {
        /**
         * Gets or sets whether this collection should detach the sync when the target collection changes.
        */
        get: function () {
            return this.i.shouldDetachOnTargetChange;
        },
        set: function (v) {
            this.i.shouldDetachOnTargetChange = ensureBool(v);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(IgrFilterExpressionCollection.prototype, "onChanged", {
        get: function () {
            return this.i.onChanged;
        },
        set: function (v) {
            this.i.onChanged = v;
        },
        enumerable: false,
        configurable: true
    });
    IgrFilterExpressionCollection.prototype.findByName = function (name) {
        if (this.findEphemera) {
            if (name && name.indexOf("@@e:") == 0) {
                return this.findEphemera(name);
            }
        }
        if (this.syncTarget != null && this.syncTarget.findByName && this.syncTarget.findByName(name)) {
            return this.syncTarget.findByName(name);
        }
        return null;
    };
    IgrFilterExpressionCollection.prototype.add = function (item) {
        var iv = this.i.add(item);
        return (iv);
    };
    IgrFilterExpressionCollection.prototype.insert = function (index, item) {
        this.i.insert(index, item);
    };
    IgrFilterExpressionCollection.prototype.clear = function () {
        this.i.clear();
    };
    IgrFilterExpressionCollection.prototype.get = function (index) {
        var iv = this.i.get(index);
        return (iv);
    };
    IgrFilterExpressionCollection.prototype.indexOf = function (item) {
        var iv = this.i.indexOf(item);
        return (iv);
    };
    IgrFilterExpressionCollection.prototype.remove = function (item) {
        var iv = this.i.remove(item);
        return (iv);
    };
    IgrFilterExpressionCollection.prototype.removeAt = function (index) {
        var iv = this.i.removeAt(index);
        return (iv);
    };
    IgrFilterExpressionCollection.prototype.set = function (index, value) {
        var iv = this.i.set(index, value);
        return (iv);
    };
    IgrFilterExpressionCollection.prototype.size = function () {
        var iv = this.i.size();
        return (iv);
    };
    return IgrFilterExpressionCollection;
}());
export { IgrFilterExpressionCollection };
