
"""
Physics Engine Skill
Provides "Impossible Physics" animation variants for Sunaiva X.
"""
from typing import Dict, Any

class PhysicsEngine:
    """
    Library of Framer Motion variants and physics constants for Sunaiva X.
    """
    
    @staticmethod
    def get_spring_config(stiffness: int = 100, damping: int = 20) -> Dict[str, int]:
        return {"type": "spring", "stiffness": stiffness, "damping": damping}

    @staticmethod
    def liquid_card_variants() -> str:
        """
        Returns the JS object string for a 'Liquid Card' that stretches on hover.
        """
        return """
        const liquidVariants = {
            rest: { scale: 1, rotateX: 0, rotateY: 0, boxShadow: "0px 10px 30px rgba(0,0,0,0.2)" },
            hover: { 
                scale: 1.02, 
                rotateX: 5, 
                rotateY: 5,
                boxShadow: "0px 20px 50px rgba(59, 130, 246, 0.3)",
                transition: { type: "spring", stiffness: 300, damping: 15 } 
            },
            tap: { scale: 0.98 }
        };
        """

    @staticmethod
    def gate_stream_variants() -> str:
        """
        Animation for the data stream particles flowing through gates.
        """
        return """
        const streamVariants = {
            initial: { pathLength: 0, opacity: 0 },
            flowing: { 
                pathLength: 1, 
                opacity: 1,
                transition: { duration: 1.5, ease: "easeInOut", repeat: Infinity, repeatType: "loop" }
            }
        };
        """

    @staticmethod
    def generate_hook_file() -> str:
        """
        Generates a useMousePhysics hook for React.
        """
        return """
        import { useMotionValue, useSpring, useTransform } from 'framer-motion';

        export const useMousePhysics = () => {
            const x = useMotionValue(0);
            const y = useMotionValue(0);

            const rotateX = useTransform(y, [-100, 100], [10, -10]);
            const rotateY = useTransform(x, [-100, 100], [-10, 10]);

            const physicsX = useSpring(rotateX, { stiffness: 150, damping: 15 });
            const physicsY = useSpring(rotateY, { stiffness: 150, damping: 15 });

            const handleMouseMove = (e) => {
                const rect = e.currentTarget.getBoundingClientRect();
                const centerX = rect.left + rect.width / 2;
                const centerY = rect.top + rect.height / 2;
                x.set(e.clientX - centerX);
                y.set(e.clientY - centerY);
            };

            const handleMouseLeave = () => {
                x.set(0);
                y.set(0);
            };

            return { physicsX, physicsY, handleMouseMove, handleMouseLeave };
        };
        """
