/*
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-react-core/ES2015/type";
import { dateMaxValue, dateMinValue, dateAddYears, dateFromValues, dateAddMonths, dateFromTicks } from "igniteui-react-core/ES2015/date";
export class FinancialChartRangeSelectorViewModel extends Base {
    constructor() {
        super(...arguments);
        this._notifyChanged = null;
        this._options = null;
        this.n = dateMaxValue();
        this.m = dateMinValue();
        this._oneMonthChecked = false;
        this._threeMonthsChecked = false;
        this._sixMonthsChecked = false;
        this._yearToDateChecked = false;
        this._oneYearChecked = false;
        this._allChecked = false;
        this.l = dateMinValue();
        this.k = dateMaxValue();
        this._onRangeChanged = null;
    }
    get notifyChanged() {
        return this._notifyChanged;
    }
    set notifyChanged(a) {
        this._notifyChanged = a;
    }
    get options() {
        return this._options;
    }
    set options(a) {
        this._options = a;
    }
    get selectionStart() {
        return this.n;
    }
    set selectionStart(a) {
        this.n = a;
    }
    get selectionEnd() {
        return this.m;
    }
    set selectionEnd(a) {
        this.m = a;
    }
    get oneMonthChecked() {
        return this._oneMonthChecked;
    }
    set oneMonthChecked(a) {
        this._oneMonthChecked = a;
    }
    get threeMonthsChecked() {
        return this._threeMonthsChecked;
    }
    set threeMonthsChecked(a) {
        this._threeMonthsChecked = a;
    }
    get sixMonthsChecked() {
        return this._sixMonthsChecked;
    }
    set sixMonthsChecked(a) {
        this._sixMonthsChecked = a;
    }
    get yearToDateChecked() {
        return this._yearToDateChecked;
    }
    set yearToDateChecked(a) {
        this._yearToDateChecked = a;
    }
    get oneYearChecked() {
        return this._oneYearChecked;
    }
    set oneYearChecked(a) {
        this._oneYearChecked = a;
    }
    get allChecked() {
        return this._allChecked;
    }
    set allChecked(a) {
        this._allChecked = a;
    }
    get rangeStart() {
        return this.l;
    }
    set rangeStart(a) {
        this.l = a;
    }
    get rangeEnd() {
        return this.k;
    }
    set rangeEnd(a) {
        this.k = a;
    }
    onPropertiesChanged() {
        let a = false;
        if (+(this.selectionEnd) == +(this.rangeEnd)) {
            if (this.allChecked != (+(this.selectionStart) == +(this.rangeStart))) {
                this.allChecked = +(this.selectionStart) == +(this.rangeStart);
                a = true;
            }
            if (this.oneYearChecked != (+(this.selectionStart) == +(this.oneYearFromEnd))) {
                this.oneYearChecked = +(this.selectionStart) == +(this.oneYearFromEnd);
                a = true;
            }
            if (this.yearToDateChecked != (+(this.selectionStart) == +(this.firstDayOfEndYear))) {
                this.yearToDateChecked = +(this.selectionStart) == +(this.firstDayOfEndYear);
                a = true;
            }
            if (this.sixMonthsChecked != (+(this.selectionStart) == +(this.sixMonthsFromEnd))) {
                this.sixMonthsChecked = +(this.selectionStart) == +(this.sixMonthsFromEnd);
                a = true;
            }
            if (this.threeMonthsChecked != (+(this.selectionStart) == +(this.threeMonthsFromEnd))) {
                this.threeMonthsChecked = +(this.selectionStart) == +(this.threeMonthsFromEnd);
                a = true;
            }
            if (this.oneMonthChecked != (+(this.selectionStart) == +(this.oneMonthFromEnd))) {
                this.oneMonthChecked = +(this.selectionStart) == +(this.oneMonthFromEnd);
                a = true;
            }
            if (a) {
                if (this.notifyChanged != null) {
                    this.notifyChanged();
                }
            }
        }
        return a;
    }
    get oneYearFromEnd() {
        return dateAddYears(this.rangeEnd, -1);
    }
    get firstDayOfEndYear() {
        return dateFromValues(this.rangeEnd.getFullYear(), 1, 1, 0, 0, 0, 0);
    }
    get sixMonthsFromEnd() {
        return dateAddMonths(this.rangeEnd, -6);
    }
    get threeMonthsFromEnd() {
        return dateAddMonths(this.rangeEnd, -3);
    }
    get oneMonthFromEnd() {
        return dateAddMonths(this.rangeEnd, -1);
    }
    changeSelection(a) {
        this.allChecked = false;
        this.oneMonthChecked = false;
        this.threeMonthsChecked = false;
        this.sixMonthsChecked = false;
        this.yearToDateChecked = false;
        this.oneYearChecked = false;
        if (a == "1m") {
            this.oneMonthChecked = true;
        }
        else if (a == "3m") {
            this.threeMonthsChecked = true;
        }
        else if (a == "6m") {
            this.sixMonthsChecked = true;
        }
        else if (a == "YTD") {
            this.yearToDateChecked = true;
        }
        else if (a == "1y") {
            this.oneYearChecked = true;
        }
        else if (a == "all") {
            this.allChecked = true;
        }
        this.onRadioButtonChanged();
    }
    onRadioButtonChanged() {
        let a = dateFromTicks(this.selectionStart.getTime());
        let b = dateFromTicks(this.selectionEnd.getTime());
        this.selectionEnd = this.rangeEnd;
        if (this.oneMonthChecked) {
            this.selectionStart = this.oneMonthFromEnd;
        }
        if (this.threeMonthsChecked) {
            this.selectionStart = this.threeMonthsFromEnd;
        }
        if (this.sixMonthsChecked) {
            this.selectionStart = this.sixMonthsFromEnd;
        }
        if (this.yearToDateChecked) {
            this.selectionStart = this.firstDayOfEndYear;
        }
        if (this.oneYearChecked) {
            this.selectionStart = this.oneYearFromEnd;
        }
        if (this.allChecked) {
            this.selectionStart = this.rangeStart;
        }
        if (+(this.selectionStart) != +a || +(this.selectionEnd) != +b) {
            this.onRangeChanged();
        }
    }
    get onRangeChanged() {
        return this._onRangeChanged;
    }
    set onRangeChanged(a) {
        this._onRangeChanged = a;
    }
}
FinancialChartRangeSelectorViewModel.$t = markType(FinancialChartRangeSelectorViewModel, 'FinancialChartRangeSelectorViewModel');
