import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { defaultImport } from "default-import";
import { FormattedMessage } from "react-intl";
import DefaultMeasure from "react-measure";
import { isInsightWidget } from "@gooddata/sdk-model";
import { DateDatasetDropdown } from "./DateDatasetDropdown.js";
import { getUnrelatedDateDataset, removeDateFromTitle } from "./utils.js";
// There are known compatibility issues between CommonJS (CJS) and ECMAScript modules (ESM).
// In ESM, default exports of CJS modules are wrapped in default properties instead of being exposed directly.
// https://github.com/microsoft/TypeScript/issues/52086#issuecomment-1385978414
const Measure = defaultImport(DefaultMeasure);
export function DateDatasetPicker({ relatedDateDatasets, selectedDateDataset, selectedDateDatasetHidden, widget, dateFromVisualization, autoOpen, isLoading, enableUnrelatedItemsVisibility, unrelatedDateDatasets, onDateDatasetChange, }) {
    const unrelatedDateDataset = relatedDateDatasets &&
        getUnrelatedDateDataset(relatedDateDatasets, selectedDateDataset, selectedDateDatasetHidden);
    const getDateFilter = (measureRef, width) => (_jsx("div", { className: "subcategory-dropdown", ref: measureRef, children: _jsx(DateDatasetDropdown, { autoOpen: autoOpen, widgetRef: widget.ref, className: "s-filter-date-dropdown", relatedDateDatasets: relatedDateDatasets ?? [], activeDateDataset: selectedDateDatasetHidden ? undefined : selectedDateDataset, unrelatedDateDataset: unrelatedDateDataset, dateFromVisualization: dateFromVisualization, onDateDatasetChange: onDateDatasetChange, isLoading: isLoading, width: width, enableUnrelatedItemsVisibility: enableUnrelatedItemsVisibility, unrelatedDateDatasets: unrelatedDateDatasets }) }));
    return (_jsxs("div", { children: [
            _jsxs("div", { className: "configuration-subcategory", children: [
                    _jsx("label", { className: "s-filter-date-dropdown-heading subcategory-label", htmlFor: "s-filter-date-dropdown", children: _jsx(FormattedMessage, { id: "configurationPanel.dateAs" }) }), _jsx(Measure, { children: ({ measureRef, contentRect }) => getDateFilter(measureRef, contentRect.entry.width || 0) })
                ] }), !!(unrelatedDateDataset && !isLoading) && (_jsx("div", { className: "gd-message error s-unrelated-date", children: isInsightWidget(widget) ? (_jsx(FormattedMessage, { id: "configurationPanel.unrelatedVizDateInfo", values: { dateDataSet: removeDateFromTitle(unrelatedDateDataset.dataSet.title) } })) : (_jsx(FormattedMessage, { id: "configurationPanel.unrelatedKpiDateInfo", values: { dateDataSet: removeDateFromTitle(unrelatedDateDataset.dataSet.title) } })) }))] }));
}
