import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { CanvasIcon, ExecutionStatusIcon } from "../index.js";
import { memo } from "react";
import { CanvasTooltip } from "../components/CanvasTooltip.js";
import { getExecutionStatusColor } from "../components/ExecutionStatusIcon/ExecutionStatusIcon.js";
import { ValidationErrorSeverity } from "../types/validation.js";
function BreakpointIndicator({ isActive = true }) {
    if (!isActive) return null;
    return /*#__PURE__*/ jsx("div", {
        className: "w-4 h-4 rounded-full bg-red-500 border border-red-600 shadow-sm",
        title: "Breakpoint"
    });
}
function ExecutionStartPointIndicator({ isActive = true }) {
    if (!isActive) return null;
    return /*#__PURE__*/ jsx("div", {
        className: "w-4 h-4 rounded-full bg-blue-500 border border-blue-600 shadow-sm",
        title: "Execution Start Point"
    });
}
function ExecutionStatusIndicatorInternal({ status, count }) {
    const isExecutedMultipleTimes = void 0 !== count && count > 1;
    const color = getExecutionStatusColor(status);
    return /*#__PURE__*/ jsxs(Fragment, {
        children: [
            isExecutedMultipleTimes && /*#__PURE__*/ jsx("span", {
                className: "text-sm pr-[2px]",
                style: {
                    color
                },
                children: count
            }),
            /*#__PURE__*/ jsx(ExecutionStatusIcon, {
                status: status
            })
        ]
    });
}
function SquareDashedIndicator() {
    return /*#__PURE__*/ jsx(CanvasTooltip, {
        content: "Node output is mocked",
        placement: "bottom",
        children: /*#__PURE__*/ jsx("span", {
            style: {
                display: 'inline-flex'
            },
            children: /*#__PURE__*/ jsx(CanvasIcon, {
                icon: "square-dashed",
                size: 16,
                color: "var(--color-foreground-emp)"
            })
        })
    });
}
const ExecutionStatusIndicator = /*#__PURE__*/ memo(ExecutionStatusIndicatorInternal);
function ValidationErrorIndicator({ message }) {
    return /*#__PURE__*/ jsx(CanvasTooltip, {
        content: message || 'Validation error',
        placement: "bottom",
        children: /*#__PURE__*/ jsx("span", {
            style: {
                display: 'inline-flex'
            },
            children: /*#__PURE__*/ jsx(CanvasIcon, {
                icon: "circle-alert",
                size: 16,
                color: "var(--canvas-error-icon)"
            })
        })
    });
}
function ValidationWarningIndicator({ message }) {
    return /*#__PURE__*/ jsx(CanvasTooltip, {
        content: message || 'Validation warning',
        placement: "bottom",
        children: /*#__PURE__*/ jsx("span", {
            style: {
                display: 'inline-flex'
            },
            children: /*#__PURE__*/ jsx(CanvasIcon, {
                icon: "triangle-alert",
                size: 16,
                color: "var(--canvas-warning-icon)"
            })
        })
    });
}
const getDefaultAdornments = (context, options)=>{
    const executionState = context.executionState;
    const status = 'object' == typeof executionState ? executionState?.status : executionState;
    const count = 'object' == typeof executionState ? executionState.count : void 0;
    const hasBreakpoint = 'object' == typeof executionState && executionState?.debug;
    const isExecutionStartPoint = 'object' == typeof executionState && executionState?.isExecutionStartPoint;
    const isOutputPinned = 'object' == typeof executionState && executionState?.isOutputPinned;
    const hasValidationError = context.validationState?.validationStatus === ValidationErrorSeverity.ERROR || context.validationState?.validationStatus === ValidationErrorSeverity.CRITICAL;
    const hasValidationWarning = context.validationState?.validationStatus === ValidationErrorSeverity.WARNING;
    const getTopRight = ()=>{
        if (!options.hideExecutionStatusAdornment && status && 'None' !== status) return /*#__PURE__*/ jsx(ExecutionStatusIndicator, {
            status: status,
            count: count
        });
        if (hasValidationError) return /*#__PURE__*/ jsx(ValidationErrorIndicator, {
            message: context.validationState?.validationError?.message
        });
        if (hasValidationWarning) return /*#__PURE__*/ jsx(ValidationWarningIndicator, {
            message: context.validationState?.validationError?.message
        });
    };
    return {
        topLeft: hasBreakpoint ? /*#__PURE__*/ jsx(BreakpointIndicator, {}) : void 0,
        topRight: getTopRight(),
        bottomLeft: isExecutionStartPoint ? /*#__PURE__*/ jsx(ExecutionStartPointIndicator, {}) : void 0,
        bottomRight: isOutputPinned ? /*#__PURE__*/ jsx(SquareDashedIndicator, {}) : void 0
    };
};
function resolveAdornments(context, options = {}) {
    return getDefaultAdornments(context, options);
}
export { BreakpointIndicator, ExecutionStartPointIndicator, ExecutionStatusIndicator, ValidationErrorIndicator, ValidationWarningIndicator, resolveAdornments };
