import React, { useEffect, useMemo, useState } from 'react';
import { ListSearch } from './ListSearch';
import { EntityAttributeEnums, LogicalSearchOperatorEnums, UdpEnums } from '../../enums/unitySystemEnums';
import { getBaseMethod, executeQueryAdHoc } from '../utilities/methodUtils';
import { useActionState } from '../../hooks/useActions';
import { useShellStore } from '../../stores/shellStore';
import { useUser } from '../../utilities/auth/useUser';
import { getSearchObject } from '../../utilities/search/SearchUtilities';
import { useTenantStore } from '../../stores/tenantStore';
export const ShortcutContentFinder = (props) => {
    const { onSelect } = props;
    const [shortcutContentOptions, setShortCutContentOptions] = useState([]);
    const actionState = useActionState();
    const { catalogPromotedEntities } = actionState;
    const shellHidden = useShellStore((state) => state.shellHidden);
    const user = useUser();
    const isProductTenant = useTenantStore((state) => state.isProductTenant);
    const shortcutContentSearchApiMethod = useMemo(() => {
        return getBaseMethod(UdpEnums.Udp_Shortcut_Content, 'unityBaseSearchMethod', catalogPromotedEntities);
    }, [catalogPromotedEntities]);
    useEffect(() => {
        const getTemplateOptions = async () => {
            var _a;
            let options = [];
            if (shortcutContentSearchApiMethod) {
                const filterElements = [];
                if (isProductTenant) {
                    filterElements.push({
                        searchField: EntityAttributeEnums.Is_Product_ShortcutContent,
                        searchValue: true,
                        searchOperator: '='
                    });
                }
                const searchObject = getSearchObject(filterElements, LogicalSearchOperatorEnums.Or, 200, true);
                const data = { data: searchObject };
                const shortcutContentResponse = await executeQueryAdHoc(data, shortcutContentSearchApiMethod.apiMethodId);
                if ((shortcutContentResponse === null || shortcutContentResponse === void 0 ? void 0 : shortcutContentResponse.status) === 200) {
                    options = (_a = shortcutContentResponse.data) === null || _a === void 0 ? void 0 : _a.pageList;
                }
            }
            setShortCutContentOptions(options);
        };
        getTemplateOptions();
    }, [
        shortcutContentSearchApiMethod,
        setShortCutContentOptions,
        user,
        isProductTenant
    ]);
    return (React.createElement(ListSearch, { items: shortcutContentOptions, onClick: onSelect, searchLabel: "Filter Shortcuts", includeTags: true, maxHeight: `calc(100vh - ${shellHidden ? '614px' : '669px'})` }));
};
//# sourceMappingURL=ShortcutContentFinder.js.map