/*
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 * as tslib_1 from "tslib";
import { DataGridCellLayoutPanel } from "./DataGridCellLayoutPanel";
import { DomWrapper_$type } from "igniteui-webcomponents-core";
import { List$1 } from "igniteui-webcomponents-core";
import { Stack$1 } from "igniteui-webcomponents-core";
import { FastIterationDictionary$2 } from "igniteui-webcomponents-core";
import { AccessibilityRow } from "./AccessibilityRow";
import { Number_$type, markType } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
var DataGridAccessibilityLayoutPanel = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(DataGridAccessibilityLayoutPanel, _super);
    function DataGridAccessibilityLayoutPanel(a, b, c) {
        var _this = _super.call(this, a, b, c) || this;
        _this.a1 = new List$1(DomWrapper_$type, 0);
        _this.a2 = new Stack$1(DomWrapper_$type);
        _this.az = new FastIterationDictionary$2(Number_$type, AccessibilityRow.$, 0);
        _this.ax = null;
        _this.a6 = null;
        _this.a6 = DataGridAccessibilityLayoutPanel.a5.toString();
        DataGridAccessibilityLayoutPanel.a5++;
        return _this;
    }
    DataGridAccessibilityLayoutPanel.prototype.refresh = function (a, b) {
        _super.prototype.refresh.call(this, a, b);
        if (this.rootElement != null) {
            var c = a.ck();
            var d = a.br.count;
            if (a.cl > 0) {
                c++;
            }
            this.rootElement.setAttribute("role", "grid");
            this.rootElement.setAttribute("aria-rowcount", c.toString());
            this.rootElement.setAttribute("aria-colcount", d.toString());
            this.rootElement.setAttribute("aria-multiselectable", "true");
        }
    };
    DataGridAccessibilityLayoutPanel.prototype.ag = function (a, b) {
        if (this.a0(a)) {
            if (a.k.g) {
                if (this.ax == null) {
                    this.ax = new AccessibilityRow();
                    this.ax.i = this.a6;
                    this.ax.e = -1;
                    this.ax.d = this.f.br.count;
                    this.ax.f = "columnheader";
                }
                this.ax.j(a, b);
            }
            else {
                var c = a.k.g ? -1 : a.k.w;
                var d = this.ay(c);
                if (d == null) {
                    d = new AccessibilityRow();
                    d.i = this.a6;
                    d.e = c;
                    d.d = this.f.br.count;
                    d.f = "gridcell";
                    this.az.s(c, d);
                }
                d.j(a, b);
            }
        }
    };
    DataGridAccessibilityLayoutPanel.prototype.ai = function (a, b) {
        if (this.a0(a)) {
            this.ba(b, "id");
            this.ba(b, "role");
            this.ba(b, "aria-colindex");
            this.ba(b, "aria-selected");
            if (a.k.g) {
                this.ba(b, "aria-sort");
            }
        }
    };
    DataGridAccessibilityLayoutPanel.prototype.ah = function (a, b) {
        if (this.a0(a)) {
            this.ag(a, b);
        }
    };
    DataGridAccessibilityLayoutPanel.prototype.am = function () {
        this.a7();
        if (this.ax != null) {
            this.a9(this.ax);
            this.ax.k();
        }
        var a = this.az.q;
        for (var b = 0; b < a.count; b++) {
            var c = a._inner[b];
            this.a9(c);
            c.k();
        }
        this.ax = null;
        this.az.u();
    };
    DataGridAccessibilityLayoutPanel.prototype.ay = function (a) {
        var b = this.az.o;
        for (var c = 0; c < b.count; c++) {
            var d = b._inner[c];
            var e = this.az.item(d);
            if (e != null && e.e == a) {
                return e;
            }
        }
        return null;
    };
    DataGridAccessibilityLayoutPanel.prototype.a3 = function () {
        if (this.a2.f > 0) {
            return this.a2.e();
        }
        return null;
    };
    DataGridAccessibilityLayoutPanel.prototype.a4 = function (a) {
        for (var b = 0; b < this.a1.count; b++) {
            var c = parseInt(this.a1._inner[b].getAttribute("aria-rowindex"));
            if (c == a.c) {
                return this.a1._inner[b];
            }
        }
        return null;
    };
    DataGridAccessibilityLayoutPanel.prototype.a9 = function (a) {
        var b = this.a4(a);
        if (b != null) {
            b.setAttribute("aria-owns", a.h());
            return;
        }
        b = this.a3();
        if (b != null) {
            b.setAttribute("aria-rowindex", a.c.toString());
            b.setAttribute("aria-owns", a.h());
            this.a8(a, b);
            return;
        }
        b = this.s.createElement("div");
        b.setAttribute("role", "row");
        b.setAttribute("aria-rowindex", a.c.toString());
        b.setAttribute("aria-owns", a.h());
        this.a8(a, b);
    };
    DataGridAccessibilityLayoutPanel.prototype.a7 = function () {
        for (var a = 0; a < this.a1.count; a++) {
            var b = this.a1._inner[a];
            var c = parseInt(b.getAttribute("aria-rowindex")) - 2;
            if (c != -1 && !this.az.d(c)) {
                b.remove();
                this.a2.h(b);
                this.a1.removeAt(a);
                a--;
            }
        }
    };
    DataGridAccessibilityLayoutPanel.prototype.a8 = function (a, b) {
        var c = -1;
        for (var d = 0; d < this.a1.count; d++) {
            var e = parseInt(this.a1._inner[d].getAttribute("aria-rowindex"));
            if (a.c < e) {
                c = d;
                break;
            }
        }
        if (c != -1) {
            var native_ = this.element.getNativeElement();
            native_.insertBefore(b.getNativeElement(), this.a1._inner[c].getNativeElement());
            this.a1.insert(c, b);
        }
        else {
            this.element.append(b);
            this.a1.add(b);
        }
    };
    DataGridAccessibilityLayoutPanel.prototype.a0 = function (a) {
        return a.k.ag || (a.k.aj && !a.k.h);
    };
    DataGridAccessibilityLayoutPanel.prototype.ba = function (a, b) {
        a.getNativeElement().removeAttribute(b);
    };
    DataGridAccessibilityLayoutPanel.$t = markType(DataGridAccessibilityLayoutPanel, 'DataGridAccessibilityLayoutPanel', DataGridCellLayoutPanel.$);
    DataGridAccessibilityLayoutPanel.a5 = 0;
    return DataGridAccessibilityLayoutPanel;
}(DataGridCellLayoutPanel));
export { DataGridAccessibilityLayoutPanel };
//# sourceMappingURL=DataGridAccessibilityLayoutPanel.js.map
