import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export function VTypeFacet({ buckets, typeRegistry, type = 'select', multiple = false }) {
    // Create a map for quick lookups of type names and counts
    const typeDataMap = new Map();
    if (!typeRegistry) {
        console.warn("Type names cannot be resolved");
    }
    buckets.forEach((bucket) => {
        let name;
        let typeId = bucket._id;
        if (bucket._id == null) {
            typeId = "Document";
            name = "Document";
        }
        else {
            name = typeRegistry?.getTypeName(bucket._id);
            if (!name) {
                console.warn("Content Object Type not found", bucket._id);
                name = bucket._id;
            }
        }
        typeDataMap.set(typeId, {
            name,
            count: bucket.count
        });
    });
    const options = buckets.map((bucket) => {
        const actualId = bucket._id;
        const displayKey = actualId || "Document";
        const typeData = typeDataMap.get(displayKey);
        return {
            value: actualId,
            label: typeData ? `${typeData.name} (${typeData.count})` : `Unknown (${bucket.count})`
        };
    });
    const customFilterGroups = {
        name: 'types',
        placeholder: 'Types',
        type: type,
        multiple: multiple,
        options: options,
        labelRenderer: (typeId) => {
            const typeData = typeDataMap.get(typeId);
            if (!typeData) {
                console.warn(`Type data not found for ${typeId}`);
                return typeId;
            }
            return (_jsxs("div", { className: "w-full flex items-center", children: [_jsx("span", { className: "text-sm truncate", children: typeData.name }), _jsxs("span", { className: "ml-2 text-xs", children: ["(", typeData.count, ")"] })] }));
        },
        filterBy: (optionValue, searchText) => {
            const typeData = typeDataMap.get(optionValue);
            if (!typeData) {
                console.warn(`Type name not found for ${optionValue}`);
                return false;
            }
            return typeData.name.toLowerCase().includes(searchText.toLowerCase());
        }
    };
    return customFilterGroups;
}
//# sourceMappingURL=VTypeFacet.js.map