import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2025-2026 GoodData Corporation
import { useMemo } from "react";
import cx from "classnames";
import { useDateAttribute } from "../hooks/useDateAttribute.js";
import { useKdaState } from "../providers/KdaState.js";
import { formatKeyDriverAnalysisDateRange, formatValue } from "../utils.js";
import { DateHeadline } from "./headlines/DateHeadline.js";
import { DiffHeadline } from "./headlines/DiffHeadline.js";
export function KdaSummaryHeadline() {
    const { state } = useKdaState();
    const definition = state.definition;
    const def = state.definition;
    const dateAttributeFinder = useDateAttribute();
    const from = state.fromValue;
    const to = state.toValue;
    const fromOpts = useMemo(() => {
        return {
            dateAttribute: dateAttributeFinder(def?.dateAttribute),
            period: def?.type ?? "previous_period",
            range: [from, from],
        };
    }, [dateAttributeFinder, def?.dateAttribute, def?.type, from]);
    const toOpts = useMemo(() => {
        return {
            dateAttribute: dateAttributeFinder(def?.dateAttribute),
            period: def?.type ?? "previous_period",
            range: [to, to],
        };
    }, [dateAttributeFinder, def?.dateAttribute, def?.type, to]);
    if (!definition || from?.value === undefined || to?.value === undefined) {
        return null;
    }
    //No items at all
    if (state.items.length === 0) {
        return null;
    }
    const diff = to.value - from.value;
    const change = diff / from.value;
    return (_jsxs("div", { className: cx("gd-kda-key-driver-headline"), children: [
            _jsx(DateHeadline, { when: formatKeyDriverAnalysisDateRange(fromOpts?.range, "-"), amount: formatValue(definition, from.value, state.separators) }), _jsx(DateHeadline, { when: formatKeyDriverAnalysisDateRange(toOpts?.range, "-"), amount: formatValue(definition, to.value, state.separators) }), _jsx(DiffHeadline, { change: change, amount: formatValue(definition, diff, state.separators) })
        ] }));
}
