import * as React from "react";
import { useFavorites } from "../../../../../hooks/useFavorites";
/**
 * Toggles the Favorite on/off when selected from the dropdown menu, then adds or removes it from the favorites folder.
 * After selection the dropdown menu is closed.
 * @param props
 */
export const ToggleFavoriteDropdown = (props) => {
    const { isFavorited, addFavorite, removeFavorite } = useFavorites();
    const { id, category, name, icon, instance } = props;
    const toggleFavorite = (e) => {
        e.preventDefault();
        e.stopPropagation();
        if (isFavorited(id)) {
            removeFavorite(id);
        }
        else {
            addFavorite({ id, category, name, icon });
        }
        instance.setState((state) => {
            return { isVisible: !state.isVisible };
        });
    };
    const favoriteValue = isFavorited(id) ? "Unfavorite" : "Favorite";
    return React.createElement("div", { onClick: toggleFavorite }, favoriteValue);
};
//# sourceMappingURL=ToggleFavoriteDropdown.js.map