import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { Spacing } from "@uipath/apollo-core";
import { Column, Row } from "../../../layouts/index.js";
import { useStore } from "../../../xyflow/react.js";
import { Button, cn } from "@uipath/apollo-wind";
import { useState } from "react";
import { CANVAS_COMPACT_BREAKPOINT } from "../../../constants.js";
import { CanvasIcon } from "../../../utils/icon-registry.js";
const RejectAllButton = ({ suggestionGroup, onClick, compact })=>/*#__PURE__*/ jsxs(Button, {
        variant: "ghost",
        size: "sm",
        onClick: ()=>onClick(suggestionGroup.id),
        className: compact ? 'text-xs min-w-0' : void 0,
        children: [
            /*#__PURE__*/ jsx(CanvasIcon, {
                icon: "x",
                size: 16
            }),
            "Reject all"
        ]
    });
const AcceptAllButton = ({ suggestionGroup, onClick, compact })=>/*#__PURE__*/ jsxs(Button, {
        size: "sm",
        onClick: ()=>onClick(suggestionGroup.id),
        className: compact ? 'text-xs min-w-0' : void 0,
        children: [
            /*#__PURE__*/ jsx(CanvasIcon, {
                icon: "check",
                size: 16
            }),
            "Accept all"
        ]
    });
const Divider = ()=>/*#__PURE__*/ jsx("div", {
        style: {
            width: 1,
            height: '24px',
            backgroundColor: 'var(--canvas-border)'
        }
    });
const SuggestionGroupNavigator = ({ currentIndex, total, onNavigateNext, onNavigatePrevious, compact })=>{
    const [isHoveringUp, setIsHoveringUp] = useState(false);
    const [isHoveringDown, setIsHoveringDown] = useState(false);
    const iconSize = compact ? 16 : 20;
    return /*#__PURE__*/ jsxs("div", {
        style: {
            display: 'flex',
            alignItems: 'center',
            gap: Spacing.SpacingMicro,
            minWidth: compact ? '80px' : '100px'
        },
        children: [
            /*#__PURE__*/ jsx(Button, {
                variant: "ghost",
                size: "icon",
                className: "h-8 w-8",
                onMouseEnter: ()=>setIsHoveringUp(true),
                onMouseLeave: ()=>setIsHoveringUp(false),
                onClick: onNavigatePrevious,
                children: /*#__PURE__*/ jsx(CanvasIcon, {
                    icon: "chevron-up",
                    color: isHoveringUp ? 'var(--canvas-primary)' : 'var(--canvas-foreground-de-emp)',
                    size: iconSize
                })
            }),
            /*#__PURE__*/ jsxs("span", {
                className: cn('font-bold text-foreground-muted', compact ? 'text-xs' : 'text-sm'),
                children: [
                    currentIndex + 1,
                    " of ",
                    total
                ]
            }),
            /*#__PURE__*/ jsx(Button, {
                variant: "ghost",
                size: "icon",
                className: "h-8 w-8",
                onMouseEnter: ()=>setIsHoveringDown(true),
                onMouseLeave: ()=>setIsHoveringDown(false),
                onClick: onNavigateNext,
                children: /*#__PURE__*/ jsx(CanvasIcon, {
                    icon: "chevron-down",
                    color: isHoveringDown ? 'var(--canvas-primary)' : 'var(--canvas-foreground-de-emp)',
                    size: iconSize
                })
            })
        ]
    });
};
const SuggestionGroupPanel = ({ suggestionGroup, onRejectAll, onAcceptAll, currentIndex = 0, onNavigateNext, onNavigatePrevious })=>{
    const canvasWidth = useStore((state)=>state.width);
    const isCompact = canvasWidth < CANVAS_COMPACT_BREAKPOINT;
    const nonStandaloneSuggestions = suggestionGroup?.suggestions.filter((s)=>!s.isStandalone) ?? [];
    const placeholderCount = nonStandaloneSuggestions.length;
    return /*#__PURE__*/ jsx(Fragment, {
        children: placeholderCount > 0 && suggestionGroup && /*#__PURE__*/ jsx(Column, {
            py: Spacing.SpacingMicro,
            px: Spacing.SpacingXs,
            gap: Spacing.SpacingXs,
            style: {
                backgroundColor: 'var(--canvas-background-secondary)',
                color: 'var(--canvas-foreground)',
                borderRadius: '8px',
                border: '1px solid var(--canvas-border-de-emp)',
                boxShadow: '0px 6px 10px rgba(0, 0, 0, 0.3)'
            },
            children: /*#__PURE__*/ jsxs(Row, {
                align: "center",
                gap: isCompact ? Spacing.SpacingXs : Spacing.SpacingS,
                justify: "space-evenly",
                style: {
                    whiteSpace: 'nowrap'
                },
                children: [
                    onRejectAll && /*#__PURE__*/ jsx(RejectAllButton, {
                        suggestionGroup: suggestionGroup,
                        onClick: onRejectAll,
                        compact: isCompact
                    }),
                    onAcceptAll && /*#__PURE__*/ jsx(AcceptAllButton, {
                        suggestionGroup: suggestionGroup,
                        onClick: onAcceptAll,
                        compact: isCompact
                    }),
                    /*#__PURE__*/ jsx(Divider, {}),
                    /*#__PURE__*/ jsx(SuggestionGroupNavigator, {
                        currentIndex: currentIndex,
                        total: placeholderCount,
                        onNavigateNext: onNavigateNext,
                        onNavigatePrevious: onNavigatePrevious,
                        compact: isCompact
                    })
                ]
            })
        })
    });
};
export { SuggestionGroupPanel };
