/*
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 { 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
 */
export let WorkbookDataObjectSaveContext = /*@__PURE__*/ (() => {
    class WorkbookDataObjectSaveContext extends Base {
        constructor(a, b, c, d) {
            super();
            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;
            let e = new Dictionary$2(String_$type, Sheet.$, 0);
            let f = new Dictionary$2(String_$type, Sheet.$, 0);
            let g = new List$1(Sheet.$, 0);
            let h = new List$1(Worksheet.$, 0);
            for (let i of fromEnum(a._worksheets$i)) {
                if (i._w) {
                    h.add(i);
                    g.add(i);
                    e.item(i.name, i);
                    f.item(i.name, i);
                }
            }
            a._hn((j, k) => {
                if (j != null && e.containsKey(j.name)) {
                    k._cc((l) => {
                        if (!f.containsKey(l.name)) {
                            g.add(l);
                            f.item(l.name, l);
                        }
                    });
                }
            }, true);
            for (let j of fromEnum(e.keys)) {
                f.removeItem(j);
            }
            this.k = f;
            this.m = new ReadOnlyCollection$1(Worksheet.$, 1, h);
            this.l = new ReadOnlyCollection$1(Sheet.$, 1, g);
            let k = a.windowOptions.selectedWorksheet;
            if (k == null || k.type == 0) {
                k = Enumerable.af(Worksheet.$, h);
            }
            if (k != null) {
                k.displayOptions._bs();
                let l = k.displayOptions._ag;
                let 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;
                }
            }
        }
        get t() {
            return this.s;
        }
        set t(a) {
            if (this.s != a) {
                if (a == null) {
                    throw new ArgumentNullException(1);
                }
                this.s = a;
            }
        }
        get e() {
            return this.c;
        }
        get f() {
            return this.d;
        }
        get n() {
            return this.l;
        }
        get o() {
            return this.m;
        }
        r(a, b) {
            this.s.setData(a, b);
        }
        g(a) {
            if (this.k.containsKey(a.name)) {
                return true;
            }
            return false;
        }
        h(a) {
            if (this.p == null) {
                return true;
            }
            if (this.j == null) {
                this.j = new Dictionary$2(String_$type, Boolean_$type, 0);
            }
            let b;
            if (!((() => { let c = this.j.tryGetValue(a, b); b = c.p1; return c.ret; })())) {
                b = this.j.item(a, this.p(a));
            }
            return b;
        }
        i() {
            if (this.q != null) {
                return this.q();
            }
            return false;
        }
    }
    WorkbookDataObjectSaveContext.$t = /*@__PURE__*/ markType(WorkbookDataObjectSaveContext, 'WorkbookDataObjectSaveContext');
    return WorkbookDataObjectSaveContext;
})();
