"use client"
import { motion } from "framer-motion";
import { useTranslations } from "next-intl";
import React from "react";

const ease = [0, 0.48, 0.22, 0.98];

const parentVariant = {
    hidden: {
        borderColor: "#D3D3D7",
        boxShadow: "0px 4px 10px rgba(0, 0, 0, 0.05)",
        backgroundColor: "hsl(0, 0%, 97%)",
    },
    visible: (delay = 0) => ({
        borderColor: ["#D3D3D7", "hsla(208, 100%, 65%, 1)", "hsla(184, 100%, 50%, 1)"],
        backgroundColor: "#fff",
        boxShadow: [
            "0px 4px 10px rgba(0, 0, 0, 0.05)",
            "0px 8px 20px rgba(0, 192, 255, 0.2)",
        ],
        transition: {
            duration: 0.5,
            ease: ease,
            repeatDelay: 1,
            repeatType: "reverse" as const,
            repeat: 1,
            delay,
        },
    }),
};

const textVariants = {
    hidden: { opacity: 0 },
    visible: (delay = 0) => ({
        opacity: 1,
        transition: {
            ease: "easeOut",
            repeatType: "reverse" as const,
            repeatDelay: 1,
            delay,
            repeat: 1,
        },
    }),
};
const childVariants = {
    hidden: { y: 0, scale: 1 },
    visible: (delay = 0) => ({
        y: [0, -2],
        scale: 1.05,
        transition: {
            duration: 0.7,
            ease: "easeOut",
            repeatType: "reverse" as const,
            repeatDelay: 1,
            delay,
            repeat: 1,
        }
    }),
};
const pathVariants = {
    hidden: { pathLength: 0, color: "#D3D3D7", },
    visible: (delay = 0) => ({
        pathLength: [0, 1],
        color: ["#D3D3D7", "hsla(184, 100%, 50%, 1)","hsla(208, 100%, 65%, 1)", ],
        transition: {
            duration: 1,
            ease: "easeInOut",
            repeatType: "reverse" as const,
            delay,
            repeatDelay: 1,
            repeat: 1,
        }
    }),
};
interface ISolutionsBox {
    title: string;
    targetAnimation: number[];
    custom: 0 | 1; // delay of animation used when the box is a receiver of the animation fixed to
    className: string;
    currentAnimation: number;
}

const LandingSolutionsMainBox = ({
    targetAnimation,
    title,
    custom,
    className,
    currentAnimation,
}: ISolutionsBox) => {
    const t = useTranslations();
    const shouldAnimate = targetAnimation.includes(currentAnimation);
    const animationKey = shouldAnimate ? `animate-${currentAnimation}` : "hidden";
    return (
        <motion.div
            key={`box-${animationKey}`} // Key resets animation
            custom={custom}
            variants={parentVariant}
            initial="hidden"
            animate={shouldAnimate ? "visible" : "hidden"}
            className={`absolute w-20 h-20 border rounded-md flex flex-col items-center justify-center text-[#D3D3D7] group hover:!text-[#4DACFF] hover:!border-[#4DACFF] hover:!shadow-lg hover:!shadow-[#4dacff41] duration-300 cursor-pointer ${className}`}
        >
            <motion.svg custom={custom} variants={childVariants} viewBox="0 0 32 28" fill="none" xmlns="http://www.w3.org/2000/svg" className='w-7 h-7 group-hover:!scale-[1.05] group-hover:!-translate-y-1 duration-300' >
                <path d="M24.5 19.8027C24.5 20.3332 24.2893 20.8419 23.9142 21.2169C23.5391 21.592 23.0304 21.8027 22.5 21.8027C21.9696 21.8027 21.4609 21.592 21.0858 21.2169C20.7107 20.8419 20.5 20.3332 20.5 19.8027C20.5 19.2723 20.7107 18.7636 21.0858 18.3885C21.4609 18.0134 21.9696 17.8027 22.5 17.8027C23.0304 17.8027 23.5391 18.0134 23.9142 18.3885C24.2893 18.7636 24.5 19.2723 24.5 19.8027ZM12.5 19.8027C12.5 20.3332 12.2893 20.8419 11.9142 21.2169C11.5391 21.592 11.0304 21.8027 10.5 21.8027C9.96957 21.8027 9.46086 21.592 9.08579 21.2169C8.71071 20.8419 8.5 20.3332 8.5 19.8027C8.5 19.2723 8.71071 18.7636 9.08579 18.3885C9.46086 18.0134 9.96957 17.8027 10.5 17.8027C11.0304 17.8027 11.5391 18.0134 11.9142 18.3885C12.2893 18.7636 12.5 19.2723 12.5 19.8027Z" fill="currentColor" />
                <path fillRule="evenodd" clipRule="evenodd" d="M6.6293 10.2587C6.83691 9.01388 7.47923 7.88299 8.44209 7.0671C9.40494 6.25122 10.6259 5.80321 11.888 5.80273H21.112C22.3742 5.80289 23.5955 6.25076 24.5587 7.06667C25.5218 7.88258 26.1643 9.01366 26.372 10.2587L26.5186 11.1361H28.5013C28.8549 11.1361 29.1941 11.2765 29.4441 11.5266C29.6942 11.7766 29.8346 12.1158 29.8346 12.4694C29.8346 12.823 29.6942 13.1622 29.4441 13.4122C29.1941 13.6623 28.8549 13.8027 28.5013 13.8027H26.964L27.08 14.4961L28.6626 16.0787C29.4128 16.8287 29.8344 17.846 29.8346 18.9067V19.8401C29.8344 20.4608 29.6897 21.0729 29.412 21.6281L28.5013 23.4507V27.1361C28.5013 27.4897 28.3608 27.8288 28.1108 28.0789C27.8607 28.3289 27.5216 28.4694 27.168 28.4694H25.8346C25.481 28.4694 25.1419 28.3289 24.8918 28.0789C24.6418 27.8288 24.5013 27.4897 24.5013 27.1361V25.8027H8.5013V27.1361C8.5013 27.4897 8.36083 27.8288 8.11078 28.0789C7.86073 28.3289 7.52159 28.4694 7.16797 28.4694H5.83464C5.48101 28.4694 5.14187 28.3289 4.89183 28.0789C4.64178 27.8288 4.5013 27.4897 4.5013 27.1361V23.4507L3.59064 21.6281C3.31312 21.0733 3.16842 20.4617 3.16797 19.8414V18.9081C3.16855 17.8478 3.5901 16.831 4.33997 16.0814L5.92264 14.4974L6.03864 13.8041H4.5013C4.14768 13.8041 3.80854 13.6636 3.55849 13.4135C3.30844 13.1635 3.16797 12.8244 3.16797 12.4707C3.16797 12.1171 3.30844 11.778 3.55849 11.5279C3.80854 11.2779 4.14768 11.1374 4.5013 11.1374H6.48264L6.6293 10.2587ZM7.71997 16.4694L6.2253 17.9641C5.97524 18.2141 5.83471 18.5531 5.83464 18.9067V19.8401C5.83486 20.047 5.88324 20.2511 5.97597 20.4361L6.9573 22.3987C7.06796 22.6202 7.23807 22.8064 7.4486 22.9367C7.65913 23.0669 7.90175 23.1359 8.1493 23.1361H24.8533C25.1008 23.1359 25.3435 23.0669 25.554 22.9367C25.7645 22.8064 25.9346 22.6202 26.0453 22.3987L27.0266 20.4361C27.1194 20.2511 27.1677 20.047 27.168 19.8401V18.9067C27.1679 18.5531 27.0274 18.2141 26.7773 17.9641L25.2826 16.4694H7.71997ZM24.26 13.8027L23.7426 10.6974C23.6389 10.0752 23.3179 9.50993 22.8368 9.10202C22.3556 8.6941 21.7454 8.46995 21.1146 8.4694H11.888C11.2574 8.47027 10.6475 8.69456 10.1667 9.10244C9.6858 9.51033 9.36503 10.0754 9.2613 10.6974L8.7413 13.8027H24.26Z" fill="currentColor" />
                <motion.path custom={custom} variants={pathVariants} d="M24.5 19.8027C24.5 20.3332 24.2893 20.8419 23.9142 21.2169C23.5391 21.592 23.0304 21.8027 22.5 21.8027C21.9696 21.8027 21.4609 21.592 21.0858 21.2169C20.7107 20.8419 20.5 20.3332 20.5 19.8027C20.5 19.2723 20.7107 18.7636 21.0858 18.3885C21.4609 18.0134 21.9696 17.8027 22.5 17.8027C23.0304 17.8027 23.5391 18.0134 23.9142 18.3885C24.2893 18.7636 24.5 19.2723 24.5 19.8027ZM12.5 19.8027C12.5 20.3332 12.2893 20.8419 11.9142 21.2169C11.5391 21.592 11.0304 21.8027 10.5 21.8027C9.96957 21.8027 9.46086 21.592 9.08579 21.2169C8.71071 20.8419 8.5 20.3332 8.5 19.8027C8.5 19.2723 8.71071 18.7636 9.08579 18.3885C9.46086 18.0134 9.96957 17.8027 10.5 17.8027C11.0304 17.8027 11.5391 18.0134 11.9142 18.3885C12.2893 18.7636 12.5 19.2723 12.5 19.8027Z" fill="currentColor" />
                <motion.path custom={custom} variants={pathVariants} fillRule="evenodd" clipRule="evenodd" d="M6.6293 10.2587C6.83691 9.01388 7.47923 7.88299 8.44209 7.0671C9.40494 6.25122 10.6259 5.80321 11.888 5.80273H21.112C22.3742 5.80289 23.5955 6.25076 24.5587 7.06667C25.5218 7.88258 26.1643 9.01366 26.372 10.2587L26.5186 11.1361H28.5013C28.8549 11.1361 29.1941 11.2765 29.4441 11.5266C29.6942 11.7766 29.8346 12.1158 29.8346 12.4694C29.8346 12.823 29.6942 13.1622 29.4441 13.4122C29.1941 13.6623 28.8549 13.8027 28.5013 13.8027H26.964L27.08 14.4961L28.6626 16.0787C29.4128 16.8287 29.8344 17.846 29.8346 18.9067V19.8401C29.8344 20.4608 29.6897 21.0729 29.412 21.6281L28.5013 23.4507V27.1361C28.5013 27.4897 28.3608 27.8288 28.1108 28.0789C27.8607 28.3289 27.5216 28.4694 27.168 28.4694H25.8346C25.481 28.4694 25.1419 28.3289 24.8918 28.0789C24.6418 27.8288 24.5013 27.4897 24.5013 27.1361V25.8027H8.5013V27.1361C8.5013 27.4897 8.36083 27.8288 8.11078 28.0789C7.86073 28.3289 7.52159 28.4694 7.16797 28.4694H5.83464C5.48101 28.4694 5.14187 28.3289 4.89183 28.0789C4.64178 27.8288 4.5013 27.4897 4.5013 27.1361V23.4507L3.59064 21.6281C3.31312 21.0733 3.16842 20.4617 3.16797 19.8414V18.9081C3.16855 17.8478 3.5901 16.831 4.33997 16.0814L5.92264 14.4974L6.03864 13.8041H4.5013C4.14768 13.8041 3.80854 13.6636 3.55849 13.4135C3.30844 13.1635 3.16797 12.8244 3.16797 12.4707C3.16797 12.1171 3.30844 11.778 3.55849 11.5279C3.80854 11.2779 4.14768 11.1374 4.5013 11.1374H6.48264L6.6293 10.2587ZM7.71997 16.4694L6.2253 17.9641C5.97524 18.2141 5.83471 18.5531 5.83464 18.9067V19.8401C5.83486 20.047 5.88324 20.2511 5.97597 20.4361L6.9573 22.3987C7.06796 22.6202 7.23807 22.8064 7.4486 22.9367C7.65913 23.0669 7.90175 23.1359 8.1493 23.1361H24.8533C25.1008 23.1359 25.3435 23.0669 25.554 22.9367C25.7645 22.8064 25.9346 22.6202 26.0453 22.3987L27.0266 20.4361C27.1194 20.2511 27.1677 20.047 27.168 19.8401V18.9067C27.1679 18.5531 27.0274 18.2141 26.7773 17.9641L25.2826 16.4694H7.71997ZM24.26 13.8027L23.7426 10.6974C23.6389 10.0752 23.3179 9.50993 22.8368 9.10202C22.3556 8.6941 21.7454 8.46995 21.1146 8.4694H11.888C11.2574 8.47027 10.6475 8.69456 10.1667 9.10244C9.6858 9.51033 9.36503 10.0754 9.2613 10.6974L8.7413 13.8027H24.26Z" fill="currentColor" />
            </motion.svg>
            <motion.h6
                key={`text-${animationKey}`}
                custom={custom}
                variants={textVariants}
                initial="hidden"
                animate={shouldAnimate ? "visible" : "hidden"}
                className="text-[12px] text-center h-0 group-hover:!opacity-100 duration-1000 text-black"
            >
                {t(title)}
            </motion.h6>
        </motion.div>
    );
};

export default LandingSolutionsMainBox;
