/*
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 getXValue(series, item) {
    return item[series.xMemberPath];
}
function getYValue(series, item) {
    return item[series.yMemberPath];
}
function hasRadius(series) {
    return series.radiusMemberPath !== undefined;
}
function getRadiusValue(series, item) {
    return item[series.radiusMemberPath];
}
function getAngleValue(series, item) {
    return item[series.angleMemberPath];
}
function hasValue(series) {
    return series.valueMemberPath;
}
function getBrush(series) {
    return series.actualBrush;
}
function hasXY(series, item) {
    return series.xMemberPath && series.yMemberPath && item[series.xMemberPath] && item[series.yMemberPath];
}
function hasColor(series) {
    return series.colorMemberPath;
}
function getColorValue(series, item) {
    return item[series.colorMemberPath];
}
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', style: { whiteSpace: "nowrap" } },
        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 ScatterTooltip = (props) => {
    if (!props.dataContext) {
        return null;
    }
    if (!props.dataContext.item) {
        return null;
    }
    const ss = props.dataContext.series;
    if (ss === null) {
        return null;
    }
    const s = ss;
    const item = props.dataContext.item;
    if (hasRadius(s)) {
        return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } },
            React.createElement("span", { style: { color: getBrush(s) } }, s.title),
            React.createElement("br", null),
            React.createElement("span", { className: "ui-tooltip-priority" },
                "(",
                getXValue(s, item),
                ", ",
                getYValue(s, item),
                "), radius: ",
                getRadiusValue(s, item))));
    }
    return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } },
        React.createElement("span", { style: { color: getBrush(s) } }, s.title),
        React.createElement("br", null),
        React.createElement("span", { className: "ui-tooltip-priority" },
            "x: ",
            getXValue(s, item)),
        React.createElement("br", null),
        React.createElement("span", { className: "ui-tooltip-priority" },
            "y: ",
            getYValue(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;
    const itemLabel = props.dataContext.itemLabel;
    return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } },
        catAxis.isDateTime && React.createElement("span", null,
            " ",
            itemLabel,
            " "),
        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("table", null,
            React.createElement("tbody", null,
                hasOpen(s) ? React.createElement("tr", null,
                    React.createElement("td", null, "Open: "),
                    React.createElement("td", null, getOpenValue(s, item))) : null,
                hasHigh(s) ? React.createElement("tr", null,
                    React.createElement("td", null, "High: "),
                    React.createElement("td", null, getHighValue(s, item))) : null,
                hasLow(s) ? React.createElement("tr", null,
                    React.createElement("td", null, "Low: "),
                    React.createElement("td", null, getLowValue(s, item))) : null,
                hasClose(s) ? React.createElement("tr", null,
                    React.createElement("td", null, "Close: "),
                    React.createElement("td", null, getCloseValue(s, item))) : null,
                hasVolume(s) ? React.createElement("tr", null,
                    React.createElement("td", null, "Volume: "),
                    React.createElement("td", null, getVolumeValue(s, item))) : null))));
};
const PolarTooltip = (props) => {
    if (!props.dataContext) {
        return null;
    }
    if (!props.dataContext.item) {
        return null;
    }
    const ss = props.dataContext.series;
    if (ss === null) {
        return null;
    }
    const s = ss;
    const item = props.dataContext.item;
    return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } },
        React.createElement("span", { className: "ui-tooltip-priority" }, getAngleValue(s, item)),
        React.createElement("br", null),
        React.createElement("span", { style: { color: getBrush(s) } },
            s.title,
            ": "),
        React.createElement("span", { className: "ui-tooltip-priority" }, getRadiusValue(s, item))));
};
const RadialTooltip = (props) => {
    if (!props.dataContext) {
        return null;
    }
    if (!props.dataContext.item) {
        return null;
    }
    const ss = props.dataContext.series;
    if (ss === null) {
        return null;
    }
    let angleAxis = ss.angleAxis;
    if (angleAxis == null) {
        return null;
    }
    const s = ss;
    const item = props.dataContext.item;
    const axisLabel = angleAxis.label;
    return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } },
        axisLabel && React.createElement("span", { className: "ui-tooltip-priority" }, axisLabel),
        axisLabel && React.createElement("br", null),
        React.createElement("span", { style: { color: getBrush(s) } },
            s.title,
            ": "),
        React.createElement("span", { className: "ui-tooltip-priority" }, getAnchoredValue(s, item))));
};
const RangeCategoryTooltip = (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 = anc.xAxis;
    if (catAxis == null) {
        return null;
    }
    const item = props.dataContext.item;
    return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } },
        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" },
            getLowValue(s, item),
            " - "),
        React.createElement("span", { className: "ui-tooltip-priority" }, getHighValue(s, item))));
};
const ShapeTooltip = (props) => {
    if (!props.dataContext) {
        return null;
    }
    if (!props.dataContext.item) {
        return null;
    }
    const ss = props.dataContext.series;
    if (ss === null) {
        return null;
    }
    const s = ss;
    const item = props.dataContext.item;
    const showXY = hasXY(s, item);
    return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } },
        React.createElement("span", { style: { color: getBrush(s) } }, s.title),
        showXY && React.createElement("br", null),
        showXY && React.createElement("span", null,
            "(",
            getXValue(s, item),
            ", ",
            getYValue(s, item),
            ") "),
        hasColor(s) && React.createElement("br", null),
        hasColor(s) && React.createElement("span", null,
            "value: ",
            getColorValue(s, item)),
        hasValue(s) && React.createElement("br", null),
        hasValue(s) && React.createElement("span", null,
            "value: ",
            item)));
};
export class IgrDataChartDefaultTooltips {
    constructor() {
        this.anchoredCategoryTooltip = AnchoredCategoryTooltip;
        this.financialTooltip = FinancialTooltip;
        this.polarTooltip = PolarTooltip;
        this.radialTooltip = RadialTooltip;
        this.rangeCategoryTooltip = RangeCategoryTooltip;
        this.scatterTooltip = ScatterTooltip;
        this.shapeTooltip = ShapeTooltip;
    }
    ensureDefaultTooltip(series) {
        if (series.isPolar) {
            if (series.showDefaultTooltip) {
                series.tooltipTemplate = this.polarTooltip;
            }
            else {
                if (series.tooltipTemplate === this.polarTooltip) {
                    series.tooltipTemplate = null;
                }
            }
        }
        else if (series.isRadial) {
            if (series.showDefaultTooltip) {
                series.tooltipTemplate = this.radialTooltip;
            }
            else {
                if (series.tooltipTemplate === this.radialTooltip) {
                    series.tooltipTemplate = null;
                }
            }
        }
        else if (series.isShape) {
            if (series.showDefaultTooltip) {
                series.tooltipTemplate = this.shapeTooltip;
            }
            else {
                if (series.tooltipTemplate === this.shapeTooltip) {
                    series.tooltipTemplate = null;
                }
            }
        }
        else if (series.isScatter) {
            if (series.showDefaultTooltip) {
                series.tooltipTemplate = this.scatterTooltip;
            }
            else {
                if (series.tooltipTemplate === this.scatterTooltip) {
                    series.tooltipTemplate = null;
                }
            }
        }
        else if (series.isCategory &&
            !series.isFinancial) {
            if (!series.isRange) {
                if (series.showDefaultTooltip) {
                    series.tooltipTemplate = this.anchoredCategoryTooltip;
                }
                else {
                    if (series.tooltipTemplate === this.anchoredCategoryTooltip) {
                        series.tooltipTemplate = null;
                    }
                }
            }
            else {
                if (series.showDefaultTooltip) {
                    series.tooltipTemplate = this.rangeCategoryTooltip;
                }
                else {
                    if (series.tooltipTemplate === this.rangeCategoryTooltip) {
                        series.tooltipTemplate = null;
                    }
                }
            }
        }
        else 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);
    }
}
