import * as React from "react";
import { SearchResult } from "./SearchResult";
import { useSearch } from "../../hooks/useSearch";
import { FEAGlobals } from "../../../common/Globals";
export const SearchProviderResults = ({ providerResponse }) => {
    var _a;
    const { searchQuery, resetSearch } = useSearch();
    const clickResetSearch = () => {
        resetSearch();
    };
    // Removes empty results then sorts by *lowest* score (search results are retuned from Finsemble where lowest is best)
    // This uses fuse.js which uses the "bitap" algorithm
    const providerResults = (_a = providerResponse === null || providerResponse === void 0 ? void 0 : providerResponse.data) === null || _a === void 0 ? void 0 : _a.filter((r) => r).sort((a, b) => a.score - b.score);
    const providerClick = () => {
        FEAGlobals.FSBL.Clients.SearchClient.invokeProviderAction(providerResponse.provider);
        resetSearch();
        FEAGlobals.finsembleWindow.blur();
    };
    return (React.createElement(React.Fragment, null,
        providerResponse && (React.createElement("div", { className: "search-title" },
            providerResponse.provider.displayName,
            providerResponse.provider.providerActionTitle && (React.createElement("div", { className: "provider-title", onClick: providerClick },
                providerResponse.provider.providerActionTitle,
                React.createElement("div", { className: "ff-arrow-right arrow_right_grey" }))))), providerResults === null || providerResults === void 0 ? void 0 :
        providerResults.map((individualResult, i) => (React.createElement(SearchResult, { key: i, resetSearch: clickResetSearch, searchQuery: searchQuery, data: individualResult })))));
};
//# sourceMappingURL=SearchProviderResults.js.map