import { jsx } from "react/jsx-runtime";
import { icons } from "lucide-react";
import { memo, useMemo } from "react";
import { AgentDiagramIcon, AgentProject, ApiProject, AutonomousAgentIcon, BusinessProcessProject, CodedAgentIcon, ConnectorBuilderProject, ControlFlowIcon, ConversationalAgentIcon, DataAndTools, DecisionIcon, FlowProject, RpaProject, SwitchIcon, UiPathIcon, WebAppProject } from "../icons/index.js";
const iconRegistry = {
    agent: ({ w, h })=>/*#__PURE__*/ jsx(AgentProject, {
            w: w ?? 29,
            h: h ?? 28
        }),
    'autonomous-agent': ({ w, h })=>/*#__PURE__*/ jsx(AutonomousAgentIcon, {
            w: w ?? 29,
            h: h ?? 28
        }),
    'conversational-agent': ({ w, h })=>/*#__PURE__*/ jsx(ConversationalAgentIcon, {
            w: w ?? 29,
            h: h ?? 28
        }),
    'coded-agent': ({ w, h })=>/*#__PURE__*/ jsx(CodedAgentIcon, {
            w: w ?? 29,
            h: h ?? 28
        }),
    connector: ({ w, h })=>/*#__PURE__*/ jsx(ConnectorBuilderProject, {
            w: w ?? 29,
            h: h ?? 28
        }),
    'data-tools': ({ w, h })=>/*#__PURE__*/ jsx(DataAndTools, {
            w: w ?? 29,
            h: h ?? 28
        }),
    'control-flow': ({ w, h })=>/*#__PURE__*/ jsx(ControlFlowIcon, {
            w: w ?? 29,
            h: h ?? 28
        }),
    'human-task': ({ w, h })=>/*#__PURE__*/ jsx(WebAppProject, {
            w: w ?? 29,
            h: h ?? 28
        }),
    rpa: ({ w, h })=>/*#__PURE__*/ jsx(RpaProject, {
            w: w ?? 29,
            h: h ?? 28
        }),
    api: ({ w, h })=>/*#__PURE__*/ jsx(ApiProject, {
            w: w ?? 29,
            h: h ?? 28
        }),
    'agentic-process': ({ w, h })=>/*#__PURE__*/ jsx(BusinessProcessProject, {
            w: w ?? 29,
            h: h ?? 28
        }),
    'flow-project': ({ w, h })=>/*#__PURE__*/ jsx(FlowProject, {
            w: w ?? 29,
            h: h ?? 28
        }),
    decision: ({ w, h })=>/*#__PURE__*/ jsx(DecisionIcon, {
            w: w ?? 24,
            h: h ?? 24
        }),
    switch: ({ w, h })=>/*#__PURE__*/ jsx(SwitchIcon, {
            w: w ?? 24,
            h: h ?? 24
        }),
    uipath: ({ w, h })=>/*#__PURE__*/ jsx(UiPathIcon, {
            w: w ?? 24,
            h: h ?? 24
        }),
    'agent-diagram': ({ w, h })=>/*#__PURE__*/ jsx(AgentDiagramIcon, {
            w: w ?? 24,
            h: h ?? 24
        })
};
function kebabToPascal(str) {
    return str.split('-').map((word)=>word.charAt(0).toUpperCase() + word.slice(1)).join('');
}
function isValidUrl(input) {
    let url;
    try {
        url = new URL(input);
    } catch (_) {
        return false;
    }
    return 'http:' === url.protocol || 'https:' === url.protocol;
}
function getIcon(iconId) {
    if (!iconId) {
        const BoxIcon = icons.Box;
        return ({ w, h, color })=>/*#__PURE__*/ jsx(BoxIcon, {
                width: w ?? 24,
                height: h ?? 24,
                color: color
            });
    }
    if (isValidUrl(iconId)) return ({ w, h })=>/*#__PURE__*/ jsx("img", {
            src: iconId,
            alt: "icon",
            style: {
                width: w,
                height: h
            }
        });
    const icon = iconRegistry[iconId];
    if (icon) return icon;
    const pascalCaseId = kebabToPascal(iconId);
    const LucideIcon = icons[pascalCaseId];
    if (LucideIcon) return ({ w, h, color })=>/*#__PURE__*/ jsx(LucideIcon, {
            width: w ?? 24,
            height: h ?? 24,
            color: color
        });
    const BoxIcon = icons.Box;
    return ({ w, h, color })=>/*#__PURE__*/ jsx(BoxIcon, {
            width: w ?? 24,
            height: h ?? 24,
            color: color
        });
}
const icon_registry_CanvasIcon = /*#__PURE__*/ memo(function({ icon, size = 16, color }) {
    const Icon = useMemo(()=>icon ? getIcon(icon) : null, [
        icon
    ]);
    if (!Icon) return null;
    return /*#__PURE__*/ jsx(Icon, {
        w: size,
        h: size,
        color: color
    });
});
const NodeIcon = icon_registry_CanvasIcon;
export { icon_registry_CanvasIcon as CanvasIcon, NodeIcon, getIcon };
