"use client"

import { FC, PropsWithChildren, ReactNode } from "react"
import { useVersionedRouter } from "@/hooks/use-versioned-router"
import { ShieldX } from "lucide-react"
import { i18n } from "@/i18n/i18n"

interface AccessDeniedProps {
  active?: boolean
  message: string
  backHref?: string
  errorComponent?: ReactNode
}

export const AccessDenied: FC<AccessDeniedProps & PropsWithChildren> = ({
  active = true,
  message,
  backHref = "/",
  errorComponent,
  children
}) => {
  const router = useVersionedRouter()

  if (!active) return children
  if (errorComponent) return errorComponent

  return (
    <div className="relative w-full min-h-screen flex items-center justify-center bg-background overflow-hidden px-4">

      <div className="absolute w-[500px] h-[500px] bg-destructive/10 blur-[120px] rounded-full top-[-200px] left-[-200px] animate-pulse" />
      <div className="absolute w-[450px] h-[450px] bg-primary/10 blur-[120px] rounded-full bottom-[-200px] right-[-200px] animate-pulse" />

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

        <div className="w-24 h-24 rounded-3xl bg-destructive/10 border border-destructive/20 flex items-center justify-center animate-bounce shadow-lg">
          <ShieldX className="w-12 h-12 text-destructive" />
        </div>

        <h1 className="my-3 text-4xl md:text-5xl font-extrabold text-foreground tracking-tight animate-fadeIn">
          دسترسی غیرمجاز
        </h1>

        <p className="text-sm md:text-base text-muted-foreground leading-relaxed animate-fadeIn delay-100">
          {message}
        </p>

        <button
          onClick={() => router.push(backHref)}
          className="mt-4 px-6 py-3 rounded-xl bg-primary text-primary-foreground font-medium hover:scale-105 active:scale-95 transition"
        >
          {i18n("common:back")}
        </button>
      </div>

      <style jsx>{`
        .animate-fadeIn {
          animation: fadeIn 0.6s ease both;
        }

        .delay-100 {
          animation-delay: 0.1s;
        }

        .delay-200 {
          animation-delay: 0.2s;
        }

        @keyframes fadeIn {
          from {
            opacity: 0;
            transform: translateY(12px);
          }
          to {
            opacity: 1;
            transform: translateY(0);
          }
        }
      `}</style>
    </div>
  )
}

export default AccessDenied