/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { h } from "@stencil/core";
import { Dimensions } from "@vertexvis/geometry";
export const TransformWidgetInputWrapper = ({ ref, bounds, viewport, point, placement, displayUnit }, children) => {
    const inputPlacement = constrainInputToViewport(viewport, bounds !== null && bounds !== void 0 ? bounds : Dimensions.create(0, 0), point, placement);
    return (h("div", { ref: ref, class: "widget-input wrapper", style: {
            ...inputPlacement,
            height: (bounds === null || bounds === void 0 ? void 0 : bounds.height) != null ? `${bounds.height}px` : undefined,
        } }, children, h("div", { class: "widget-input units" }, displayUnit.unit.abbreviatedName)));
};
export const TransformWidgetInput = ({ ref, identifier, disabled, onChange, onIncrement, onDecrement, onBlur, onUndo, }) => {
    const handleChange = (event) => {
        if (event.target != null) {
            const parsed = parseFloat(event.target.value);
            if (!isNaN(parsed)) {
                onChange === null || onChange === void 0 ? void 0 : onChange(parseFloat(event.target.value));
            }
        }
    };
    const handleKeyDown = (event) => {
        const commandOrControlModifier = event.ctrlKey || event.metaKey;
        if (event.key === 'ArrowUp') {
            onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
        }
        else if (event.key === 'ArrowDown') {
            onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
        }
        else if (event.key === 'z' && commandOrControlModifier && onUndo) {
            event.preventDefault();
            onUndo();
        }
    };
    return (h("input", { ref: ref, disabled: disabled, class: `widget-input ${identifier}`, type: "text", onChange: handleChange, onKeyDown: handleKeyDown, onBlur: onBlur }));
};
function constrainTo(dimension, length) {
    return Math.min(dimension, Math.max(0, length));
}
function constrainInputToViewport(viewport, inputDimensions, point, placement, padding = 5) {
    const { width, height } = viewport.dimensions;
    const paddedWidth = inputDimensions.width + padding;
    const paddedHeight = inputDimensions.height + padding;
    function toCssLength(length) {
        return `${length}px`;
    }
    switch (placement) {
        case 'top-left':
            return {
                right: toCssLength(constrainTo(width - paddedWidth, width - point.x)),
                bottom: toCssLength(constrainTo(height - paddedHeight, height - point.y)),
            };
        case 'top-right':
            return {
                left: toCssLength(constrainTo(width - paddedWidth, point.x)),
                bottom: toCssLength(constrainTo(height - paddedHeight, height - point.y)),
            };
        case 'bottom-left':
            return {
                right: toCssLength(constrainTo(width - paddedWidth, width - point.x)),
                top: toCssLength(constrainTo(height - paddedHeight, point.y)),
            };
        case 'bottom-right':
        default:
            return {
                left: toCssLength(constrainTo(width - paddedWidth, point.x)),
                top: toCssLength(constrainTo(height - paddedHeight, point.y)),
            };
    }
}
//# sourceMappingURL=viewer-transform-widget-components.js.map
