/*
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, markType } from "igniteui-angular-core";
import { ConditionBase } from "./ConditionBase";
import { FormulaContext } from "./FormulaContext";
import { FormulaStringGenerator } from "./FormulaStringGenerator";
import { FormulaConditionalFormat } from "./FormulaConditionalFormat";
import { CellAddress } from "./CellAddress";
import { stringIsNullOrEmpty, stringEmpty } from "igniteui-angular-core";
import { stringFormat } from "igniteui-angular-core";
/**
 * @hidden
 */
export class ConditionalFormattingUtils extends Base {
    static g(a) {
        let b = a.formula;
        if (b == null) {
            return null;
        }
        let c = b._aa;
        if (b == null) {
            return null;
        }
        let d = new FormulaContext(4, a.worksheet, c.o, c.m, 2, b, null, 1);
        let e = FormulaStringGenerator.bj(d);
        let f = e.a2();
        return FormulaConditionalFormat._ca(f.b);
    }
    static d(a) {
        let b = a._s().p(true, true, 2, 1);
        if (stringIsNullOrEmpty(b)) {
            return null;
        }
        let c = null;
        let d = null;
        switch (a.conditionType) {
            case 9:
                c = stringFormat("LEN(TRIM({0}))=0", b);
                break;
            case 12:
                c = stringFormat("LEN(TRIM({0}))>0", b);
                break;
            case 13:
                c = stringFormat("ISERROR({0})", b);
                break;
            case 14:
                c = stringFormat("NOT(ISERROR({0}))", b);
                break;
            case 7:
            case 6:
                d = ConditionBase._a1(a.worksheet, a.regions, 1, false, false);
                let e = a.conditionType == 7 ? ">" : "=";
                c = stringFormat("AND(COUNTIF({0}, {1}){2}1,NOT(ISBLANK({1})))", d, b, e);
                break;
            case 11:
                c = stringFormat("AVERAGE({0})", b);
                break;
            default:
                c = null;
                break;
        }
        return c;
    }
    static f(a) {
        let b = a._s().p(true, true, 2, 1);
        if (stringIsNullOrEmpty(b)) {
            return null;
        }
        let c = null;
        let d = a.text != null ? a.text : stringEmpty();
        let e = a.textOperator;
        switch (e) {
            case 2:
                c = stringFormat("NOT(ISERROR(SEARCH(\"{0}\",{1})))", d, b);
                break;
            case 3:
                c = stringFormat("ISERROR(SEARCH(\"{0}\",{1}))", d, b);
                break;
            case 0:
                c = stringFormat("LEFT({1},LEN(\"{0}\"))=\"{0}\"", d, b);
                break;
            case 1:
                c = stringFormat("RIGHT({1},LEN(\"{0}\"))=\"{0}\"", d, b);
                break;
            default:
                c = null;
                break;
        }
        return c;
    }
    static e(a) {
        let b = a._s().p(true, true, 2, 1);
        if (stringIsNullOrEmpty(b)) {
            return null;
        }
        let c = null;
        switch (a.dateOperator) {
            case 2:
                c = stringFormat("FLOOR({0},1)=TODAY()-1", b);
                break;
            case 0:
                c = stringFormat("FLOOR({0},1)=TODAY()", b);
                break;
            case 1:
                c = stringFormat("FLOOR({0},1)=TODAY()+1", b);
                break;
            case 9:
                c = stringFormat("AND(MONTH({0})=MONTH(EDATE(TODAY(),0-1)),YEAR({0})=YEAR(EDATE(TODAY(),0-1)))", b);
                break;
            case 8:
                c = stringFormat("AND(MONTH({0})=MONTH(EDATE(TODAY(),0+1)),YEAR({0})=YEAR(EDATE(TODAY(),0+1)))", b);
                break;
            case 7:
                c = stringFormat("AND(MONTH({0})=MONTH(TODAY()),YEAR({0})=YEAR(TODAY()))", b);
                break;
            case 6:
                c = stringFormat("AND(TODAY()-FLOOR({0},1)<=6,FLOOR({0},1)<=TODAY())", b);
                break;
            case 5:
                c = stringFormat("AND(TODAY()-ROUNDDOWN({0},0)>=(WEEKDAY(TODAY())),TODAY()-ROUNDDOWN({0},0)<(WEEKDAY(TODAY())+7))", b);
                break;
            case 4:
                c = stringFormat("AND(ROUNDDOWN({0},0)-TODAY()>(7-WEEKDAY(TODAY())),ROUNDDOWN({0},0)-TODAY()<(15-WEEKDAY(TODAY())))", b);
                break;
            case 3:
                c = stringFormat("AND(TODAY()-ROUNDDOWN({0},0)<=WEEKDAY(TODAY())-1,ROUNDDOWN({0},0)-TODAY()<=7-WEEKDAY(TODAY()))", b);
                break;
            default:
                c = null;
                break;
        }
        return c;
    }
    static a(a) {
        return ConditionalFormattingUtils.c(a.regions);
    }
    static c(a) {
        return a.count > 0 ? ConditionalFormattingUtils.b(a.item(0)) : null;
    }
    static b(a) {
        return CellAddress.u(a.firstRow, a.firstColumn);
    }
}
ConditionalFormattingUtils.$t = markType(ConditionalFormattingUtils, 'ConditionalFormattingUtils');
//# sourceMappingURL=ConditionalFormattingUtils.js.map