/*
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, Point_$type, markType } from "igniteui-angular-core";
import { IVerticalAnchoredCategorySeriesInteractionManager_$type } from "./IVerticalAnchoredCategorySeriesInteractionManager";
import { Rect } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { ArrayExtension } from "igniteui-angular-core";
/**
 * @hidden
 */
export let VerticalAnchoredCategorySeriesInteractionManager = /*@__PURE__*/ (() => {
    class VerticalAnchoredCategorySeriesInteractionManager extends Base {
        e$a(a, b) {
            let c = a.cd != null ? a.cd.s9 : Rect.empty;
            let d = a.b0.bu;
            let e = a.pv(a.b0);
            let f = a.getEffectiveViewport1(a.b0);
            let g = a.ar();
            let h = -1;
            if (g != null && !c.isEmpty && !d.isEmpty) {
                let i = new ScalerParams(0, c, d, g.cg, f);
                let j = g.el(e.top, i);
                let k = g.el(e.bottom, i);
                let l = (b.y - c.top) / c.height;
                let m = j + (l * (k - j));
                if (g.categoryMode != 0) {
                    m -= 0.5;
                }
                h = m;
            }
            return h;
        }
        e$b(a, b, c, d) {
            if (b == null || b.count == 0) {
                return Rect.empty;
            }
            let e = a.pl(c);
            let f = -1;
            let g = a.ar().cg;
            let h = a.b0.bu.bottom * 2;
            if (g) {
                f = ArrayExtension.binarySearch$11(Point_$type, b, (i) => (h - e.y) < (h - i.y) ? -1 : ((h - e.y) > (h - i.y) ? 1 : 0));
            }
            else {
                f = ArrayExtension.binarySearch$11(Point_$type, b, (i) => e.y < i.y ? -1 : (e.y > i.y ? 1 : 0));
            }
            if (f < 0) {
                f = ~f;
            }
            if (f < 0) {
                f = 0;
            }
            if (f > b.count - 1) {
                f = b.count - 1;
            }
            let i = f;
            let j = f;
            if (i > 0) {
                i--;
            }
            if (j < b.count - 1) {
                j++;
            }
            let k = b._inner[i].y;
            let l = b._inner[f].y;
            let m = b._inner[j].y;
            let n = Math.abs(k - e.y);
            let o = Math.abs(l - e.y);
            let p = Math.abs(m - e.y);
            let q = d(i);
            let r = d(f);
            let s = d(j);
            let t = q.containsPoint(e);
            let u = r.containsPoint(e);
            let v = s.containsPoint(e);
            if (o <= n && o <= p) {
                if (!g && v) {
                    return s;
                }
                if (g && t) {
                    return q;
                }
                return r;
            }
            if (n <= o && n <= p) {
                if (!g && u) {
                    return r;
                }
                return d(i);
            }
            if (p <= o && p <= n) {
                if (g && u) {
                    return r;
                }
                return d(j);
            }
            return Rect.empty;
        }
    }
    VerticalAnchoredCategorySeriesInteractionManager.$t = markType(VerticalAnchoredCategorySeriesInteractionManager, 'VerticalAnchoredCategorySeriesInteractionManager', Base.$, [IVerticalAnchoredCategorySeriesInteractionManager_$type]);
    return VerticalAnchoredCategorySeriesInteractionManager;
})();
