/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends, __values } from "tslib";
import { Base, String_$type, fromEnum, Boolean_$type, markType } from "igniteui-webcomponents-core";
import { ArgumentNullException } from "igniteui-webcomponents-core";
import { Sheet } from "igniteui-webcomponents-excel";
import { Worksheet } from "igniteui-webcomponents-excel";
import { List$1 } from "igniteui-webcomponents-core";
import { CoreUtilities } from "./CoreUtilities";
import { Dictionary$2 } from "igniteui-webcomponents-core";
import { ReadOnlyCollection$1 } from "igniteui-webcomponents-core";
import { Enumerable } from "igniteui-webcomponents-core";
import { WorksheetRegionAddress } from "igniteui-webcomponents-excel";
import { CellRegionMapSingle } from "./CellRegionMapSingle";
import { CellRegionMapMany } from "./CellRegionMapMany";
/**
 * @hidden
 */
var WorkbookDataObjectSaveContext = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(WorkbookDataObjectSaveContext, _super);
    function WorkbookDataObjectSaveContext(a, b, c, d) {
        var e_1, _a, e_2, _b;
        var _this = _super.call(this) || this;
        _this.s = null;
        _this.j = null;
        _this.k = null;
        _this.p = null;
        _this.q = null;
        _this.m = null;
        _this.l = null;
        _this.c = false;
        _this.d = false;
        _this.a = null;
        _this.b = null;
        CoreUtilities.z(a, "workbook");
        _this.b = a;
        _this.p = c;
        _this.q = d;
        _this.t = b;
        var e = new Dictionary$2(String_$type, Sheet.$, 0);
        var f = new Dictionary$2(String_$type, Sheet.$, 0);
        var g = new List$1(Sheet.$, 0);
        var h = new List$1(Worksheet.$, 0);
        try {
            for (var _c = __values(fromEnum(a._worksheets$i)), _d = _c.next(); !_d.done; _d = _c.next()) {
                var i = _d.value;
                if (i._w) {
                    h.add(i);
                    g.add(i);
                    e.item(i.name, i);
                    f.item(i.name, i);
                }
            }
        }
        catch (e_1_1) {
            e_1 = { error: e_1_1 };
        }
        finally {
            try {
                if (_d && !_d.done && (_a = _c.return))
                    _a.call(_c);
            }
            finally {
                if (e_1)
                    throw e_1.error;
            }
        }
        a._hn(function (j, k) {
            if (j != null && e.containsKey(j.name)) {
                k._cc(function (l) {
                    if (!f.containsKey(l.name)) {
                        g.add(l);
                        f.item(l.name, l);
                    }
                });
            }
        }, true);
        try {
            for (var _e = __values(fromEnum(e.keys)), _f = _e.next(); !_f.done; _f = _e.next()) {
                var j = _f.value;
                f.removeItem(j);
            }
        }
        catch (e_2_1) {
            e_2 = { error: e_2_1 };
        }
        finally {
            try {
                if (_f && !_f.done && (_b = _e.return))
                    _b.call(_e);
            }
            finally {
                if (e_2)
                    throw e_2.error;
            }
        }
        _this.k = f;
        _this.m = new ReadOnlyCollection$1(Worksheet.$, 1, h);
        _this.l = new ReadOnlyCollection$1(Sheet.$, 1, g);
        var k = a.windowOptions.selectedWorksheet;
        if (k == null || k.type == 0) {
            k = Enumerable.af(Worksheet.$, h);
        }
        if (k != null) {
            k.displayOptions._bs();
            var l = k.displayOptions._ag;
            var m = l.a(k.displayOptions._aa);
            if (m != null) {
                if (m.d.count == 1) {
                    _this.a = new CellRegionMapSingle(m.d.item(0));
                }
                else {
                    _this.a = new CellRegionMapMany(Enumerable.a(WorksheetRegionAddress.$, m.d));
                }
                _this.c = _this.a.c.length == 1 && _this.a.c[0]._i == 0 && _this.a.c[0]._h >= k._rows$i.maxCount - 1;
                _this.d = _this.a.a.length == 1 && _this.a.a[0]._i == 0 && _this.a.a[0]._h >= k._columns$i.maxCount - 1;
            }
        }
        return _this;
    }
    Object.defineProperty(WorkbookDataObjectSaveContext.prototype, "t", {
        get: function () {
            return this.s;
        },
        set: function (a) {
            if (this.s != a) {
                if (a == null) {
                    throw new ArgumentNullException(1);
                }
                this.s = a;
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(WorkbookDataObjectSaveContext.prototype, "e", {
        get: function () {
            return this.c;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(WorkbookDataObjectSaveContext.prototype, "f", {
        get: function () {
            return this.d;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(WorkbookDataObjectSaveContext.prototype, "n", {
        get: function () {
            return this.l;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(WorkbookDataObjectSaveContext.prototype, "o", {
        get: function () {
            return this.m;
        },
        enumerable: false,
        configurable: true
    });
    WorkbookDataObjectSaveContext.prototype.r = function (a, b) {
        this.s.setData(a, b);
    };
    WorkbookDataObjectSaveContext.prototype.g = function (a) {
        if (this.k.containsKey(a.name)) {
            return true;
        }
        return false;
    };
    WorkbookDataObjectSaveContext.prototype.h = function (a) {
        var _this = this;
        if (this.p == null) {
            return true;
        }
        if (this.j == null) {
            this.j = new Dictionary$2(String_$type, Boolean_$type, 0);
        }
        var b;
        if (!((function () { var c = _this.j.tryGetValue(a, b); b = c.p1; return c.ret; })())) {
            b = this.j.item(a, this.p(a));
        }
        return b;
    };
    WorkbookDataObjectSaveContext.prototype.i = function () {
        if (this.q != null) {
            return this.q();
        }
        return false;
    };
    WorkbookDataObjectSaveContext.$t = markType(WorkbookDataObjectSaveContext, 'WorkbookDataObjectSaveContext');
    return WorkbookDataObjectSaveContext;
}(Base));
export { WorkbookDataObjectSaveContext };
