// seekora-ui-sdk/packages/react/src/layout/context-wired-props.tsx
import * as React from "react";
export const DrawerContext = React.createContext(null);
export function DrawerProvider({ children, }) {
    const [isOpen, setOpen] = React.useState(false);
    const value = React.useMemo(() => ({ isOpen, setOpen }), [isOpen]);
    return (React.createElement(DrawerContext.Provider, { value: value }, children));
}
export const ThemeHarvestContext = React.createContext(null);
export function applyContextWiredProps(componentName, baseProps, drawer, themeHarvest) {
    let props = baseProps;
    // Inject drawer-wired props.
    if (drawer) {
        switch (componentName) {
            case "MobileFiltersButton":
                props = { ...props, onClick: () => drawer.setOpen(true) };
                break;
            case "MobileFilters":
                props = {
                    ...props,
                    isOpen: drawer.isOpen,
                    onClose: () => drawer.setOpen(false),
                };
                break;
            default:
                break;
        }
    }
    // Inject harvest template, swap map, and money_format as defaults on
    // SearchResults when the caller didn't explicitly set them in the config
    // spec's props. SCRUM-267.
    if (componentName === "SearchResults" &&
        themeHarvest &&
        !props.themeHarvestTemplate) {
        props = {
            ...props,
            themeHarvestTemplate: themeHarvest.cardTemplateHtml,
            themeHarvestSwapMap: themeHarvest.swapMap,
            ...(themeHarvest.moneyFormat
                ? { themeHarvestMoneyFormat: themeHarvest.moneyFormat }
                : {}),
        };
    }
    // Inject predictive row template, swap map, and money_format into
    // ThemeHarvestPredictiveList when the context carries harvested predictive
    // data and the props weren't already explicitly set. SCRUM-267.
    if (componentName === "ThemeHarvestPredictiveList" &&
        themeHarvest &&
        themeHarvest.predictiveCardTemplateHtml &&
        themeHarvest.predictiveSwapMap &&
        !props.cardTemplateHtml) {
        props = {
            ...props,
            cardTemplateHtml: themeHarvest.predictiveCardTemplateHtml,
            swapMap: themeHarvest.predictiveSwapMap,
            ...(themeHarvest.moneyFormat
                ? { moneyFormat: themeHarvest.moneyFormat }
                : {}),
            ...(themeHarvest.predictiveListClass
                ? { listClassName: themeHarvest.predictiveListClass }
                : {}),
        };
    }
    if (componentName === "ThemeHarvestSuggestionList" &&
        themeHarvest &&
        themeHarvest.suggestionChipTemplateHtml &&
        themeHarvest.suggestionChipSwap &&
        !props.chipTemplateHtml) {
        props = {
            ...props,
            chipTemplateHtml: themeHarvest.suggestionChipTemplateHtml,
            chipSwap: themeHarvest.suggestionChipSwap,
            ...(themeHarvest.suggestionListClass
                ? { listClassName: themeHarvest.suggestionListClass }
                : {}),
        };
    }
    return props;
}
