"use client"

import type React from "react"
import { useEffect, useState } from "react"
import { useIonRouter } from '@ionic/react';

const CourseComplete: React.FC = () => {

  const [animationPhase, setAnimationPhase] = useState(0)

  useEffect(() => {
    const timer1 = setTimeout(() => setAnimationPhase(1), 500)
    const timer2 = setTimeout(() => setAnimationPhase(2), 1500)
    const timer3 = setTimeout(() => setAnimationPhase(3), 2000)
    const timer4 = setTimeout(() => setAnimationPhase(4), 2500)

    return () => {
      clearTimeout(timer1)
      clearTimeout(timer2)
      clearTimeout(timer3)
      clearTimeout(timer4)
    }
  }, [])




  const router = useIonRouter()

    useEffect(() => {
      const timer = setTimeout(() => {
        router.push("/home", "forward")
      }, 3500) // Задержка 3 секунды

      return () => clearTimeout(timer)
    }, [router])


  return (



    <div className="min-h-screen bg-gradient-to-br from-[#3ABBC7] to-[#0D212C] flex items-center justify-center">
      {/* Men Animation */}


      <div className="min-h-screen p-4 relative overflow-hidden max-w-2xl mx-auto">



        
        <div className="absolute inset-0 flex items-start justify-center pt-30 w-[400px] h-[1100px]">
          {/* тело */}
          <div className={`absolute left-[37%] transform duration-800 delay-300 ${animationPhase >= 1 ? "opacity-100 scale-100 top-[24%]" : "opacity-0 scale-0 top-[10%]"} `}>
            <svg xmlns="http://www.w3.org/2000/svg" width="100" height="158" viewBox="0 0 100 158" fill="none">
              <rect width="100" height="158" rx="60" fill="#F3945B" />
            </svg>
          </div>

          {/* руки */}
          <div className={`absolute left-[15%] transition-all duration-800 delay-300 ${animationPhase >= 1 ? "opacity-100 scale-100 top-[16%]" : "opacity-0 scale-0 top-[20%]"}  ${animationPhase >= 3 ? "opacity-100 rotate-20" : "opacity-100 rotate-0"}`}
          >
            <svg xmlns="http://www.w3.org/2000/svg" width="292" height="221" viewBox="0 0 292 221" fill="none">
              <path d="M26 78.0571C43.5001 101.057 67.9999 122.5 111 129C154 135.5 164 119.557 202.5 138.557C241 157.557 248.5 188.057 252 203.057C255.5 218.057 270 221.057 277.5 220.057C285 219.057 289.5 212.557 291 206.057C292.5 199.557 287.5 159.557 246.5 121.557C205.5 83.5571 174 95.0575 114.5 89.5571C55.0001 84.0568 39.5 24.0576 34 9.55715C28.5001 -4.94333 -1.70972e-05 -2.94326 0 15.5571C1.70972e-05 34.0576 8.49988 55.0571 26 78.0571Z" fill="#F3945B" />
            </svg>
          </div>

          {/* нога 1 */}
          <div className={`absolute transition-all duration-800 delay-300 ${animationPhase >= 1 ? "opacity-100 scale-100 top-[30%] left-[37%]" : "opacity-0 scale-0 top-[15%] left-[47%]"} ${animationPhase >= 3 ? "top-[0%] right-[47%] " : "top-[15%] right-[47%] "}`}>
            <svg xmlns="http://www.w3.org/2000/svg" width="37" height="129" viewBox="0 0 37 129" fill="none">
              <rect width="37" height="129" rx="18.5" fill="#F3945B" />
            </svg>
            <div className="top-[75%] left-[2%] absolute">
              <svg xmlns="http://www.w3.org/2000/svg" width="35" height="120" viewBox="0 0 35 140" fill="#F3945B">
                <rect x="0" y="10" width="35" height="30" fill="#F3945B" rx="12" /> 
                <rect x="15" y="40" width="7" height="50" fill="#F3945B" />
                <circle cx="18.5" cy="90" r="8" fill="#F3945B" />
              </svg>
            </div>
          </div>

          {/* нога 2 */}
          <div className={`absolute transition-all duration-800 delay-300 ${animationPhase >= 1 ? "opacity-100 scale-100 top-[30%] right-[38%] " : "opacity-0 scale-0 top-[15%] right-[47%] "} `}>
            <svg xmlns="http://www.w3.org/2000/svg" width="37" height="178" viewBox="0 0 37 178" fill="none">
              <rect width="37" height="178" rx="18.5" fill="#F3945B" />
            </svg>
          </div>

          {/* голова */}
          <div className={`absolute transition-all duration-800 delay-300 ${animationPhase >= 1 ? "opacity-100 scale-100 top-[16%] left-[41%] " : "opacity-0 scale-0 top-[20%] right-[40%] "} `}>
            <svg xmlns="http://www.w3.org/2000/svg" width="75" height="75" viewBox="0 0 75 75" fill="none">
              <circle cx={37.5} cy={37.5} r={37.5} fill="#F3945B" />
            </svg>
          </div>

           

          {/* мяч */}
          <div className={`z-50 absolute transition-all duration-600 delay-100 ${animationPhase >= 2 ? "opacity-100 scale-100 top-[14%] left-[22%] " : "opacity-0 scale-0 -top-[20%] right-[40%] "} ${animationPhase >= 3 ? "scale-[90%]" : "scale-100"}    ${animationPhase >= 4 ? "scale-[3000%]" : "scale-100"}
        
          ` }
          >
            <svg xmlns='http://www.w3.org/2000/svg' width='54' height='54' viewBox='0 0 54 54' fill='none'>
              <circle cx='27' cy='27' r='27' fill='#FFFFFF' />
            </svg>
          </div>
        </div>



        <div className="text-center z-10 max-w-md">

          {/* Main Content */}
          <div className="flex items-center justify-center min-h-screen">
            <div className="text-center px-8 z-10">

              <div
                className={`transition-opacity duration-1000 delay-600 ${animationPhase >= 1 ? "opacity-100" : "opacity-0"}`}
              >
                <h1 className="text-5xl font-black text-white mb-4 tracking-tight filter drop-shadow-lg">Реабилитация</h1>

                <div
                  className="h-1 bg-white/70 rounded-full mx-auto my-2 transition-all duration-500 ease-out"
                  style={{
                    width: animationPhase >= 2 ? '320px' : '0px', 
                    maxWidth: '320px',
                    opacity: animationPhase >= 2 ? 1 : 0,
                  }}
                ></div>

                <p className={`text-white/90 text-xl font-medium tracking-wide transition-opacity duration-1000 ${animationPhase >= 2 ? 'opacity-100' : 'opacity-0'}`}>
                  Восстановление через движение
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div >
  )
}

export default CourseComplete


            // <svg xmlns="http://www.w3.org/2000/svg" width="292" height="221" viewBox="0 0 292 221" fill="none">
            //   <path d="M26 78.0571C43.5001 101.057 67.9999 122.5 111 129C154 135.5 164 119.557 202.5 138.557C241 157.557 248.5 188.057 252 203.057C255.5 218.057 270 221.057 277.5 220.057C285 219.057 289.5 212.557 291 206.057C292.5 199.557 287.5 159.557 246.5 121.557C205.5 83.5571 174 95.0575 114.5 89.5571C55.0001 84.0568 39.5 24.0576 34 9.55715C28.5001 -4.94333 -1.70972e-05 -2.94326 0 15.5571C1.70972e-05 34.0576 8.49988 55.0571 26 78.0571Z" fill="#F3945B" />
            // </svg>