import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2024-2026 GoodData Corporation
import { useState } from "react";
import { FormattedMessage, defineMessage, useIntl } from "react-intl";
import { Bubble, BubbleHoverTrigger, Button, ContentDivider, Dropdown, } from "@gooddata/sdk-ui-kit";
import { DEFAULT_DROPDOWN_ALIGN_POINTS } from "../../constants.js";
import { AttachmentFiltersList } from "./AttachmentFiltersList.js";
const TOOLTIP_ALIGN_POINTS = [
    {
        align: "cr cl",
        offset: { x: 0, y: -2 },
    },
    {
        align: "cl cr",
        offset: { x: 0, y: -2 },
    },
];
const buttonTitle = {
    edited: defineMessage({ id: "dialogs.schedule.management.attachments.filters.edited" }).id,
    default: defineMessage({ id: "dialogs.schedule.management.attachments.filters.default" }).id,
};
export function AttachmentFilters({ filterType, onChange, hidden = false, disabled = false, filters, overlayPositionType, }) {
    const [selectedType, setSelectedType] = useState(filterType);
    const intl = useIntl();
    const handleTypeChange = (type) => {
        if (!disabled) {
            setSelectedType(type);
        }
    };
    const isDefaultDisabled = selectedType !== "default" && disabled;
    const defaultFiltersTooltipMessage = isDefaultDisabled
        ? defineMessage({
            id: "dialogs.schedule.management.attachments.filters.item.tooltip.disabled",
        })
        : defineMessage({ id: "dialogs.schedule.management.attachments.filters.item.tooltip" });
    if (hidden) {
        return null;
    }
    return (_jsx(Dropdown, { overlayPositionType: overlayPositionType, alignPoints: DEFAULT_DROPDOWN_ALIGN_POINTS, renderButton: ({ toggleDropdown }) => (_jsxs("div", { className: "gd-attachment-filters-dropdown-button", children: [
                _jsx(FormattedMessage, { id: "dialogs.schedule.management.attachments.filters.using" }), _jsx(Button, { className: "gd-button-link-dimmed s-attachment-filters-dropdown-button", value: intl.formatMessage({ id: buttonTitle[filterType] }), onClick: toggleDropdown })
            ] })), renderBody: ({ closeDropdown }) => (_jsxs("div", { className: "gd-attachment-filters-dropdown", children: [
                _jsxs("div", { className: "gd-list-title", children: [
                        _jsx(FormattedMessage, { id: "dialogs.schedule.management.attachments.filters.title" }), _jsx("div", { className: "gd-close-button", children: _jsx(Button, { className: "gd-button-link gd-button-icon-only gd-icon-cross s-dialog-close-button", value: "", onClick: closeDropdown }) })
                    ] }), _jsxs("div", { className: "gd-attachment-filters-dropdown-content", children: [
                        _jsxs("label", { className: "input-radio-label", children: [
                                _jsx("input", { type: "radio", className: "input-radio", name: "filterType", onChange: () => handleTypeChange("edited"), checked: selectedType === "edited", disabled: selectedType !== "edited" && disabled }), _jsx("span", { className: "input-label-text", children: _jsx(FormattedMessage, { id: "dialogs.schedule.management.attachments.filters.item.edited" }) })
                            ] }), _jsx(AttachmentFiltersList, { filters: filters }), _jsxs("label", { className: "input-radio-label", children: [
                                _jsx("input", { type: "radio", className: "input-radio", name: "filterType", onChange: () => handleTypeChange("default"), checked: selectedType === "default", disabled: isDefaultDisabled }), _jsxs("span", { className: "input-label-text", children: [
                                        _jsx(FormattedMessage, { id: "dialogs.schedule.management.attachments.filters.item.default" }), _jsxs(BubbleHoverTrigger, { children: [
                                                _jsx("span", { className: "gd-icon-circle-question" }), _jsx(Bubble, { alignPoints: TOOLTIP_ALIGN_POINTS, children: _jsx(FormattedMessage, { id: defaultFiltersTooltipMessage.id }) })
                                            ] })
                                    ] })
                            ] })
                    ] }), _jsx(ContentDivider, { className: "gd-divider-without-margin" }), _jsxs("div", { className: "gd-attachment-filters-dropdown-footer", children: [
                        _jsx(Button, { value: intl.formatMessage({ id: "cancel" }), className: "gd-button-secondary", onClick: closeDropdown }), _jsx(Button, { value: intl.formatMessage({ id: "save" }), className: "gd-button-action", onClick: () => {
                                onChange(selectedType);
                                closeDropdown();
                            }, disabled: selectedType === filterType })
                    ] })
            ] })) }));
}
//# sourceMappingURL=AttachmentFilters.js.map