"use client"

import type React from "react"

import Link from "next/link"
import { usePathname } from "next/navigation"
import { LayoutDashboard, FileText, Users, CreditCard, QrCode, Settings, LogOut, Wallet } from "lucide-react"
import { useStore } from "@/lib/store"
import { useRouter } from "next/navigation"
import { useEffect } from "react"

export default function AdminLayout({ children }: { children: React.ReactNode }) {
  const pathname = usePathname()
  const router = useRouter()
  const { user, isLoggedIn } = useStore()

  useEffect(() => {
    if (!isLoggedIn) {
      // router.push("/my")
    }
  }, [isLoggedIn, router])

  const menuItems = [
    { icon: LayoutDashboard, label: "数据概览", href: "/admin" },
    { icon: FileText, label: "内容管理", href: "/admin/content" },
    { icon: Users, label: "用户管理", href: "/admin/users" },
    { icon: CreditCard, label: "支付配置", href: "/admin/payment" },
    { icon: Wallet, label: "提现管理", href: "/admin/withdrawals" },
    { icon: QrCode, label: "二维码", href: "/admin/qrcodes" },
    { icon: Settings, label: "系统设置", href: "/admin/settings" },
  ]

  return (
    <div className="flex min-h-screen bg-[#0a1628]">
      {/* Sidebar - 深色侧边栏 */}
      <div className="w-64 bg-[#0f2137] flex flex-col border-r border-gray-700/50 shadow-xl">
        <div className="p-6 border-b border-gray-700/50">
          <h1 className="text-xl font-bold text-[#38bdac]">管理后台</h1>
          <p className="text-xs text-gray-400 mt-1">Soul创业实验场</p>
        </div>

        <nav className="flex-1 p-4 space-y-1">
          {menuItems.map((item) => {
            const isActive = pathname === item.href
            return (
              <Link
                key={item.href}
                href={item.href}
                className={`flex items-center gap-3 px-4 py-3 rounded-lg transition-colors ${
                  isActive
                    ? "bg-[#38bdac]/20 text-[#38bdac] font-medium"
                    : "text-gray-400 hover:bg-gray-700/50 hover:text-white"
                }`}
              >
                <item.icon className="w-5 h-5" />
                <span className="text-sm">{item.label}</span>
              </Link>
            )
          })}
        </nav>

        <div className="p-4 border-t border-gray-700/50">
          <Link
            href="/"
            className="flex items-center gap-3 px-4 py-3 text-gray-400 hover:text-white rounded-lg hover:bg-gray-700/50 transition-colors"
          >
            <LogOut className="w-5 h-5" />
            <span className="text-sm">返回前台</span>
          </Link>
        </div>
      </div>

      {/* Main Content - 深色背景 */}
      <div className="flex-1 overflow-auto bg-[#0a1628]">{children}</div>
    </div>
  )
}
