"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RolloverModifierRenderableSeriesProps = void 0;
var Deleter_1 = require("../../../../Core/Deleter");
var rolloverTooltipSvgAnnotationHelpers_1 = require("../../Annotations/rolloverTooltipSvgAnnotationHelpers");
var SciChartSurfaceBase_1 = require("../../SciChartSurfaceBase");
var constants_1 = require("./constants");
var RolloverModifierRenderableSeriesProps = /** @class */ (function () {
    function RolloverModifierRenderableSeriesProps(renderableSeries, isY1) {
        if (isY1 === void 0) { isY1 = false; }
        this.tooltipLegendOffsetX = 20;
        this.tooltipLegendOffsetY = 20;
        this.showsRolloverProperty = true;
        this.tooltipTextColorProperty = SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME.textAnnotationForeground;
        this.renderableSeries = renderableSeries;
        this.isY1 = isY1;
    }
    RolloverModifierRenderableSeriesProps.copy = function (from, to) {
        to.markerColorProperty = from.markerColor;
        to.showsRolloverProperty = from.showRollover;
        to.tooltipColorProperty = from.tooltipColor;
        to.tooltipDataTemplateProperty = from.tooltipDataTemplate;
        to.tooltipLabelX = from.tooltipLabelX;
        to.tooltipLabelY = from.tooltipLabelY;
        to.tooltipLegendOffsetX = from.tooltipLegendOffsetX;
        to.tooltipLegendOffsetY = from.tooltipLegendOffsetY;
        to.tooltipTemplate = from.tooltipTemplate;
        to.tooltipTextColorProperty = from.tooltipTextColorProperty;
        to.tooltipTitleProperty = from.tooltipTitle;
        to.shadowColorProperty = from.shadowColorProperty;
        to.invalidateParentCallback = from.invalidateParentCallback;
    };
    RolloverModifierRenderableSeriesProps.prototype.setInvalidateParentCallback = function (callback) {
        this.invalidateParentCallback = callback;
    };
    Object.defineProperty(RolloverModifierRenderableSeriesProps.prototype, "showRollover", {
        get: function () {
            return this.showsRolloverProperty;
        },
        set: function (value) {
            this.showsRolloverProperty = value;
            this.notifyPropertyChanged(constants_1.PROPERTY.SHOWS_ROLLOVER);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RolloverModifierRenderableSeriesProps.prototype, "tooltipColor", {
        get: function () {
            if (this.tooltipColorProperty) {
                return this.tooltipColorProperty;
            }
            else if (this.getRenderableSeriesStroke()) {
                return this.getRenderableSeriesStroke();
            }
            else {
                return SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME.textAnnotationBackground;
            }
        },
        set: function (value) {
            this.tooltipColorProperty = value;
            this.notifyPropertyChanged(constants_1.PROPERTY.TOOLTIP_COLOR);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RolloverModifierRenderableSeriesProps.prototype, "tooltipTextColor", {
        get: function () {
            return this.tooltipTextColorProperty;
        },
        set: function (value) {
            this.tooltipTextColorProperty = value;
            this.notifyPropertyChanged(constants_1.PROPERTY.TOOLTIP_TEXT_COLOR);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RolloverModifierRenderableSeriesProps.prototype, "tooltipTitle", {
        get: function () {
            return this.tooltipTitleProperty;
        },
        set: function (value) {
            this.tooltipTitleProperty = value;
            this.notifyPropertyChanged(constants_1.PROPERTY.TOOLTIP_TITLE);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RolloverModifierRenderableSeriesProps.prototype, "markerColor", {
        get: function () {
            if (this.markerColorProperty) {
                return this.markerColorProperty;
            }
            else if (this.getRenderableSeriesStroke()) {
                return this.getRenderableSeriesStroke();
            }
            else {
                return SciChartSurfaceBase_1.SciChartSurfaceBase.DEFAULT_THEME.textAnnotationBackground;
            }
        },
        set: function (value) {
            this.markerColorProperty = value;
            this.notifyPropertyChanged(constants_1.PROPERTY.MARKER_COLOR);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RolloverModifierRenderableSeriesProps.prototype, "shadowColor", {
        get: function () {
            return this.shadowColorProperty;
        },
        set: function (value) {
            this.shadowColorProperty = value;
            this.notifyPropertyChanged(constants_1.PROPERTY.TOOLTIP_SHADOW_COLOR);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RolloverModifierRenderableSeriesProps.prototype, "tooltipDataTemplate", {
        get: function () {
            return this.tooltipDataTemplateProperty;
        },
        set: function (value) {
            this.tooltipDataTemplateProperty = value;
            this.notifyPropertyChanged(constants_1.PROPERTY.TOOLTIP_DATA_TEMPLATE);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(RolloverModifierRenderableSeriesProps.prototype, "tooltipLegendTemplate", {
        get: function () {
            return this.tooltipLegendTemplateProperty;
        },
        // TODO: remove in version 2.0
        set: function (value) {
            console.warn("tooltipLegendTemplate property on the RolloverModifierRenderableSeriesProps will be removed in version 2.0, please set tooltipLegendTemplate on the RolloverModifier instead");
            this.tooltipLegendTemplateProperty = value;
        },
        enumerable: false,
        configurable: true
    });
    /**
     * Calculates tooltip width from the longest text line length.
     * Override this if using a custom tooltipTemplate with different sizing.
     */
    RolloverModifierRenderableSeriesProps.prototype.calcTooltipWidth = function (textLength) {
        return (0, rolloverTooltipSvgAnnotationHelpers_1.calcTooltipWidth)(textLength);
    };
    /**
     * Calculates tooltip height from the number of text lines.
     * Override this if using a custom tooltipTemplate with different sizing.
     */
    RolloverModifierRenderableSeriesProps.prototype.calcTooltipHeight = function (lines) {
        return (0, rolloverTooltipSvgAnnotationHelpers_1.calcTooltipHeight)(lines);
    };
    /**
     * Pre-computes tooltip text lines and dimensions.
     * Called by calcTooltipProps before positioning to ensure correct first-render placement.
     * The resulting lines are cached on the tooltip annotation to avoid recomputation in the SVG template.
     */
    RolloverModifierRenderableSeriesProps.prototype.getTooltipSize = function (seriesInfo) {
        var _a, _b, _c, _d, _e;
        var dataTemplate = (_c = (_a = this.tooltipDataTemplate) !== null && _a !== void 0 ? _a : (_b = this.rolloverModifier) === null || _b === void 0 ? void 0 : _b.tooltipDataTemplate) !== null && _c !== void 0 ? _c : rolloverTooltipSvgAnnotationHelpers_1.defaultTooltipDataTemplate;
        var lines = dataTemplate(seriesInfo, this.tooltipTitle, this.tooltipLabelX, this.tooltipLabelY);
        // Cache lines on the annotation so the SVG template can reuse them
        if (this.tooltip) {
            this.tooltip.tooltipLines = lines;
        }
        var maxLen = lines.reduce(function (prev, cur) { return ((cur === null || cur === void 0 ? void 0 : cur.length) > prev ? cur.length : prev); }, 0);
        var width = (_d = this.width) !== null && _d !== void 0 ? _d : this.calcTooltipWidth(maxLen);
        var height = (_e = this.height) !== null && _e !== void 0 ? _e : this.calcTooltipHeight(lines.length);
        return { width: width, height: height };
    };
    RolloverModifierRenderableSeriesProps.prototype.delete = function () {
        var _a, _b;
        this.rolloverModifier = undefined;
        if (!((_a = this.marker) === null || _a === void 0 ? void 0 : _a.isDeleted)) {
            this.marker = (0, Deleter_1.deleteSafe)(this.marker);
        }
        this.marker = undefined;
        if (!((_b = this.tooltip) === null || _b === void 0 ? void 0 : _b.isDeleted)) {
            this.tooltip = (0, Deleter_1.deleteSafe)(this.tooltip);
        }
        this.tooltip = undefined;
    };
    RolloverModifierRenderableSeriesProps.prototype.notifyPropertyChanged = function (propertyName) {
        if (this.invalidateParentCallback) {
            this.invalidateParentCallback();
        }
    };
    RolloverModifierRenderableSeriesProps.prototype.getRenderableSeriesStroke = function () {
        if (this.isY1) {
            var bandRS = this.renderableSeries;
            // @ts-ignore
            return bandRS.strokeY1Property;
        }
        // Get property here to retain Auto_Color prefix
        // @ts-ignore
        return this.renderableSeries.strokeProperty;
    };
    return RolloverModifierRenderableSeriesProps;
}());
exports.RolloverModifierRenderableSeriesProps = RolloverModifierRenderableSeriesProps;
