import { getFieldValueCaption } from "../../../../utils/field-utils.js";
import { renderFacetValueBox } from "../facet-value-box/facet-value-box.js";
import { renderFacetValueCheckbox } from "../facet-value-checkbox/facet-value-checkbox.js";
import { renderFacetValueLabelHighlight } from "../facet-value-label-highlight/facet-value-label-highlight.js";
import { renderFacetValueLink } from "../facet-value-link/facet-value-link.js";
const renderFacetValue = ({ props: { facetSearchQuery, displayValuesAs, enableExclusion, facetCount, facetState, facetValue, field, i18n, onExclude, onSelect, setRef } })=>{
    const displayValue = getFieldValueCaption(field, facetValue, i18n);
    const isSelected = 'selected' === facetState;
    const isExcluded = 'excluded' === facetState;
    const triStateProps = enableExclusion ? {
        onExclude,
        state: facetState
    } : {};
    switch(displayValuesAs){
        case 'checkbox':
            return renderFacetValueCheckbox({
                props: {
                    ...triStateProps,
                    displayValue,
                    numberOfResults: facetCount,
                    isSelected,
                    i18n,
                    onClick: onSelect,
                    searchQuery: facetSearchQuery,
                    buttonRef: (element)=>{
                        setRef?.(element);
                    }
                }
            })(renderFacetValueLabelHighlight({
                props: {
                    displayValue,
                    isSelected,
                    isExcluded,
                    searchQuery: facetSearchQuery
                }
            }));
        case 'link':
            return renderFacetValueLink({
                props: {
                    displayValue,
                    numberOfResults: facetCount,
                    isSelected,
                    i18n,
                    onClick: onSelect,
                    searchQuery: facetSearchQuery,
                    buttonRef: (element)=>{
                        setRef?.(element);
                    }
                }
            })(renderFacetValueLabelHighlight({
                props: {
                    displayValue,
                    isSelected,
                    searchQuery: facetSearchQuery
                }
            }));
        case 'box':
            return renderFacetValueBox({
                props: {
                    displayValue,
                    numberOfResults: facetCount,
                    isSelected,
                    i18n,
                    onClick: onSelect,
                    searchQuery: facetSearchQuery,
                    buttonRef: (element)=>{
                        setRef?.(element);
                    }
                }
            })(renderFacetValueLabelHighlight({
                props: {
                    displayValue,
                    isSelected,
                    searchQuery: facetSearchQuery
                }
            }));
    }
};
export { renderFacetValue };
