import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { useState } from "react";
import cx from "classnames";
import { FormattedMessage } from "react-intl";
import { areObjRefsEqual, isDashboardDateFilterReference, isInsightWidget, objRefToString, } from "@gooddata/sdk-model";
import { ShortenedText } from "@gooddata/sdk-ui-kit";
import { simplifyText } from "@gooddata/util";
import { useDashboardSelector } from "../../../../model/react/DashboardStoreProvider.js";
import { selectAllCatalogDateDatasetsMap } from "../../../../model/store/catalog/catalogSelectors.js";
import { useCurrentDateFilterConfig } from "../../../dragAndDrop/useCurrentDateFilterConfig.js";
import { useDateFilterConfigurationHandling } from "./useDateFilterConfigurationHandling.js";
const tooltipAlignPoints = [{ align: "cl cr", offset: { x: -20, y: 0 } }];
export function DateFilterConfigurationItem({ widget, dataSetRef }) {
    const [isApplied, setIsApplied] = useState(() => !widget.ignoreDashboardFilters.some((reference) => {
        if (!isDashboardDateFilterReference(reference)) {
            return false;
        }
        return areObjRefsEqual(reference.dataSet, dataSetRef);
    }));
    const ddsMap = useDashboardSelector(selectAllCatalogDateDatasetsMap);
    const dateDataSetTitle = ddsMap.get(dataSetRef)?.dataSet.title || "Date";
    const { title } = useCurrentDateFilterConfig(dataSetRef, dateDataSetTitle);
    const isFilterNotApplied = false; // Execution warnings are not used on Tiger which only supports Multiple DFs
    const { handleIgnoreChanged, status } = useDateFilterConfigurationHandling(widget, [], setIsApplied, dataSetRef);
    const isError = isApplied && (status === "error" || isFilterNotApplied);
    const isLoading = status === "loading";
    const classNames = cx("s-attribute-filter-by-item", `s-${simplifyText(title)}`, "input-checkbox-label", "filter-by-item", "attribute-filter-by-item", {
        "attribute-filter-error": isError,
    });
    const uniqueKey = objRefToString(dataSetRef);
    return (_jsxs("div", { children: [
            _jsxs("label", { className: classNames, htmlFor: uniqueKey, children: [
                    _jsx("input", { id: uniqueKey, type: "checkbox", className: "input-checkbox", checked: isApplied, onChange: (e) => handleIgnoreChanged(e.target.checked) }), _jsx("span", { className: "input-label-text", children: _jsx(ShortenedText, { tooltipAlignPoints: tooltipAlignPoints, tagName: "span", className: "title", children: title }) }), isLoading ? _jsx("div", { className: "gd-spinner small" }) : null] }), !!isError && (_jsx("div", { className: "gd-message error s-not-applied-attribute-filter", children: isInsightWidget(widget) ? (_jsx(FormattedMessage, { id: "configurationPanel.vizCantBeFilteredByDate", values: { attributeName: title } })) : (_jsx(FormattedMessage, { id: "configurationPanel.kpiCantBeFilteredByDate", values: { attributeName: title } })) }))] }));
}
//# sourceMappingURL=DateFilterConfigurationItem.js.map