/*
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 React from 'react';
import { TypeRegistrar } from "igniteui-react-core/ES2015/type";
function hasOpen(series) {
    return series.openMemberPath;
}
function getOpenValue(series, item) {
    return item[series.openMemberPath];
}
function hasHigh(series) {
    return series.highMemberPath;
}
function getHighValue(series, item) {
    return item[series.highMemberPath];
}
function hasLow(series) {
    return series.lowMemberPath;
}
function getLowValue(series, item) {
    return item[series.lowMemberPath];
}
function hasClose(series) {
    return series.closeMemberPath;
}
function getCloseValue(series, item) {
    return item[series.closeMemberPath];
}
function hasVolume(series) {
    return series.volumeMemberPath;
}
function getVolumeValue(series, item) {
    return item[series.volumeMemberPath];
}
function getAnchoredValue(series, item) {
    return item[series.valueMemberPath];
}
function getBrush(series) {
    return series.actualBrush;
}
function asAny(item) {
    return item;
}
function format(value) {
    if (value.getTime) {
        return shortDate(value);
    }
    return value.toString();
}
function shortDate(item) {
    return item.toLocaleDateString() + " " + item.toLocaleTimeString();
}
const AnchoredCategoryTooltip = (props) => {
    if (!props.dataContext) {
        return null;
    }
    if (!props.dataContext.item) {
        return null;
    }
    const anc = props.dataContext.series;
    if (anc === null) {
        return null;
    }
    const s = anc;
    let catAxis = null;
    if (anc.isVertical) {
        catAxis = anc.yAxis;
    }
    else {
        catAxis = anc.xAxis;
    }
    if (catAxis == null) {
        return null;
    }
    const item = props.dataContext.item;
    return (React.createElement("div", { className: 'ui-chart-default-tooltip-content' },
        catAxis.isDateTime && React.createElement("span", null, shortDate(asAny(props.dataContext.item)[asAny(catAxis).dateTimeMemberPath])),
        catAxis.isDateTime && React.createElement("br", null),
        (!catAxis.isDateTime && catAxis.label) && React.createElement("span", null, format(asAny(item)[catAxis.label])),
        (!catAxis.isDateTime && catAxis.label) && React.createElement("br", null),
        React.createElement("span", { style: { color: getBrush(s) } },
            s.title,
            ": "),
        React.createElement("span", { className: "ui-tooltip-priority" }, getAnchoredValue(s, item))));
};
const FinancialTooltip = (props) => {
    if (!props.dataContext) {
        return null;
    }
    if (!props.dataContext.item) {
        return null;
    }
    const fin = props.dataContext.series;
    if (fin === null) {
        return null;
    }
    const s = fin;
    const catAxis = fin.xAxis;
    if (catAxis == null) {
        return null;
    }
    const item = props.dataContext.item;
    return (React.createElement("div", { className: 'ui-chart-default-tooltip-content' },
        catAxis.isDateTime && React.createElement("span", null,
            " ",
            shortDate(asAny(props.dataContext.item)[asAny(s.xAxis).dateTimeMemberPath]),
            " "),
        catAxis.isDateTime && React.createElement("br", null),
        (!catAxis.isDateTime && catAxis.label) && React.createElement("span", null, format(asAny(item)[catAxis.label])),
        (!catAxis.isDateTime && catAxis.label) && React.createElement("br", null),
        React.createElement("table", null,
            hasOpen(s) && React.createElement("tr", null,
                React.createElement("td", null, "Open:"),
                React.createElement("td", null, getOpenValue(s, item))),
            hasHigh(s) && React.createElement("tr", null,
                React.createElement("td", null, "High:"),
                React.createElement("td", null, getHighValue(s, item))),
            hasLow(s) && React.createElement("tr", null,
                React.createElement("td", null, "Low:"),
                React.createElement("td", null, getLowValue(s, item))),
            hasClose(s) && React.createElement("tr", null,
                React.createElement("td", null, "Close:"),
                React.createElement("td", null, getCloseValue(s, item))),
            hasVolume(s) && React.createElement("tr", null,
                React.createElement("td", null, "Volume:"),
                React.createElement("td", null, getVolumeValue(s, item))))));
};
export class IgrDataChartDefaultTooltips {
    constructor() {
        this.anchoredCategoryTooltip = AnchoredCategoryTooltip;
        this.financialTooltip = FinancialTooltip;
    }
    ensureDefaultTooltip(series) {
        if (series.isCategory &&
            !series.isVertical &&
            !series.isFinancial &&
            !series.isRange) {
            if (series.showDefaultTooltip) {
                series.tooltipTemplate = this.anchoredCategoryTooltip;
            }
            else {
                if (series.tooltipTemplate === this.anchoredCategoryTooltip) {
                    series.tooltipTemplate = null;
                }
            }
        }
        if (series.isFinancial) {
            if (series.showDefaultTooltip) {
                series.tooltipTemplate = this.financialTooltip;
            }
            else {
                if (series.tooltipTemplate === this.financialTooltip) {
                    series.tooltipTemplate = null;
                }
            }
        }
    }
    static register() {
        TypeRegistrar.registerCons("IgrDataChartDefaultTooltips", IgrDataChartDefaultTooltips);
    }
}
