"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLongestLegendFormattedValueSelector = void 0;
const compute_series_domains_1 = require("./compute_series_domains");
const get_specs_1 = require("./get_specs");
const create_selector_1 = require("../../../../state/create_selector");
const get_settings_spec_1 = require("../../../../state/selectors/get_settings_spec");
const axis_utils_1 = require("../../utils/axis_utils");
const spec_1 = require("../utils/spec");
exports.getLongestLegendFormattedValueSelector = (0, create_selector_1.createCustomCachedSelector)([compute_series_domains_1.computeFullSeriesDomainsSelector, get_specs_1.getSeriesSpecsSelector, get_specs_1.getAxisSpecsSelector, get_settings_spec_1.getSettingsSpecSelector], ({ yDomains }, seriesSpecs, axesSpecs, settings) => {
    const maxYValue = yDomains?.[0]?.domain?.[1];
    if (typeof maxYValue !== 'number' || !isFinite(maxYValue))
        return undefined;
    let result;
    for (const spec of seriesSpecs) {
        const { yAxis } = (0, spec_1.getAxesSpecForSpecId)(axesSpecs, spec.groupId, settings.rotation);
        const formatter = spec.tickFormat ?? yAxis?.tickFormat ?? axis_utils_1.defaultTickFormatter;
        const formatted = formatter(maxYValue);
        if (!result || formatted.length > result.length) {
            result = formatted;
        }
    }
    return result;
});
//# sourceMappingURL=get_legend_max_formatted_value.js.map