import { animate } from "motion";
const ANIMATION_CONSTANTS = {
    MAX_ZOOM: 3,
    NODE_FOCUS_PADDING: 0.1,
    DEFAULT_CANVAS_WIDTH: 800,
    DEFAULT_CANVAS_HEIGHT: 600,
    TRANSITION_TIMEOUT: 5000
};
const TRANSITION_CONFIG = {
    drillDuration: 0.4,
    viewportDuration: 0.3,
    easing: {
        drillIn: [
            0.4,
            0,
            0.2,
            1
        ],
        drillOut: [
            0.4,
            0,
            0.2,
            1
        ],
        viewport: [
            0.25,
            0.1,
            0.25,
            1
        ]
    }
};
function calculateNodeFocusViewport(nodeBounds, canvasSize, padding = 0.1) {
    const paddingX = canvasSize.width * padding;
    const paddingY = canvasSize.height * padding;
    const availableWidth = canvasSize.width - 2 * paddingX;
    const availableHeight = canvasSize.height - 2 * paddingY;
    const scaleX = availableWidth / nodeBounds.width;
    const scaleY = availableHeight / nodeBounds.height;
    const zoom = Math.min(scaleX, scaleY, ANIMATION_CONSTANTS.MAX_ZOOM);
    const centerX = nodeBounds.x + nodeBounds.width / 2;
    const centerY = nodeBounds.y + nodeBounds.height / 2;
    const x = canvasSize.width / 2 - centerX * zoom;
    const y = canvasSize.height / 2 - centerY * zoom;
    return {
        x,
        y,
        zoom
    };
}
async function animateViewport(fromViewport, toViewport, duration = TRANSITION_CONFIG.viewportDuration, onUpdate, onComplete) {
    return new Promise((resolve)=>{
        animate(fromViewport, toViewport, {
            duration,
            ease: TRANSITION_CONFIG.easing.viewport,
            onUpdate: (latest)=>{
                if (onUpdate) onUpdate(latest);
            },
            onComplete: ()=>{
                if (onComplete) onComplete();
                resolve();
            }
        });
    });
}
async function animateDrillIn(fromViewport, nodeViewport, onUpdate, onComplete) {
    return new Promise((resolve)=>{
        animate(fromViewport, nodeViewport, {
            duration: TRANSITION_CONFIG.drillDuration,
            ease: TRANSITION_CONFIG.easing.drillIn,
            onUpdate: (latest)=>{
                if (onUpdate) onUpdate(latest);
            },
            onComplete: ()=>{
                if (onComplete) onComplete();
                resolve();
            }
        });
    });
}
async function animateDrillOut(fromViewport, parentViewport, onUpdate, onComplete) {
    return new Promise((resolve)=>{
        animate(fromViewport, parentViewport, {
            duration: TRANSITION_CONFIG.drillDuration,
            ease: TRANSITION_CONFIG.easing.drillOut,
            onUpdate: (latest)=>{
                if (onUpdate) onUpdate(latest);
            },
            onComplete: ()=>{
                if (onComplete) onComplete();
                resolve();
            }
        });
    });
}
function getCanvasSize(containerElement) {
    if (!containerElement) return {
        width: ANIMATION_CONSTANTS.DEFAULT_CANVAS_WIDTH,
        height: ANIMATION_CONSTANTS.DEFAULT_CANVAS_HEIGHT
    };
    const rect = containerElement.getBoundingClientRect();
    return {
        width: rect.width || ANIMATION_CONSTANTS.DEFAULT_CANVAS_WIDTH,
        height: rect.height || ANIMATION_CONSTANTS.DEFAULT_CANVAS_HEIGHT
    };
}
function prefersReducedMotion() {
    if ("u" < typeof window) return false;
    const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
    return mediaQuery.matches;
}
export { ANIMATION_CONSTANTS, TRANSITION_CONFIG, animateDrillIn, animateDrillOut, animateViewport, calculateNodeFocusViewport, getCanvasSize, prefersReducedMotion };
