import { jsx as _jsx } from "react/jsx-runtime";
import { Icon, iconNames } from "../../../ui/components/icon/index.js";
import { useMemo } from "react";
const DEFAULT_ICON_NAME = "GlobeWww";
const UrlFavicon = ({ url, platformIcons }) => {
    const IconToUse = useMemo(() => {
        const defaultIcon = _jsx(Icon, { name: DEFAULT_ICON_NAME, size: 18 });
        try {
            const parsedUrl = new URL(url);
            const hostname = parsedUrl.hostname;
            const icon = platformIcons?.[hostname];
            if (!icon)
                return defaultIcon;
            if (typeof icon === "string") {
                // check beyond typescript check if the icon actually exists
                if (iconNames.includes(icon)) {
                    return _jsx(Icon, { name: icon, size: 18 });
                }
                else {
                    console.error(`Platform icon "${icon}" does not exist`);
                    return defaultIcon;
                }
            }
            return icon;
        }
        catch {
            return defaultIcon;
        }
    }, [url, platformIcons]);
    if (Object.keys(platformIcons ?? {}).length === 0)
        return null;
    return (_jsx("div", { className: "absolute left-2.5 top-0 flex h-full items-center justify-center text-gray-900", children: IconToUse }));
};
export default UrlFavicon;
//# sourceMappingURL=url-favicon.js.map