"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useIconPack = useIconPack;
const react_1 = require("react");
function useIconPack() {
    const [iconPacks, setIconPacks] = (0, react_1.useState)({});
    const [loading, setLoading] = (0, react_1.useState)(true);
    const [error, setError] = (0, react_1.useState)(null);
    (0, react_1.useEffect)(() => {
        const fetchIconPacks = async () => {
            try {
                const response = await fetch(' / api / ui - icons / packs');
                if (!response.ok) {
                    throw new Error('Failed to fetch icon packs');
                }
                const data = await response.json();
                setIconPacks(data);
            }
            catch (err) {
                setError(err instanceof Error ? err : new Error('Unknown error'));
            }
            finally {
                setLoading(false);
            }
        };
        fetchIconPacks();
    }, []);
    const getIcon = (iconId) => {
        const [packId, iconName] = iconId.split(':');
        if (!packId || !iconName || !iconPacks[packId]) {
            return null;
        }
        const pack = iconPacks[packId];
        const label = pack.icons[iconName];
        if (!label) {
            return null;
        }
        return {
            pack: packId,
            name: iconName,
            label,
        };
    };
    return {
        iconPacks,
        loading,
        error,
        getIcon,
    };
}
//# sourceMappingURL=useIconPack.js.map