"use client"

import Link from "next/link"
import { AuthGuard } from "@/components/auth-guard"
import { DashboardSidebar } from "@/components/dashboard-sidebar"
import { Header } from "@/components/header"
import { Button } from "@/components/ui/button"
import { useAuthStore } from "@/store/auth"

export default function DashboardLayout({ children }: { children: React.ReactNode }) {
  const isAuthenticated = useAuthStore((state) => state.isAuthenticated)
  const currentRole = useAuthStore((state) => state.currentRole)

  return (
    <div className="flex min-h-screen flex-col">
      <Header />
      <div className="container mx-auto flex flex-1 px-4">
        <div className="hidden md:block">
          <DashboardSidebar />
        </div>
        <main className="flex-1 p-6">
          <AuthGuard>
            {isAuthenticated && currentRole === "consumer" ? (
              <div className="flex min-h-[50vh] items-center justify-center">
                <Button asChild>
                  <Link href="/">发现</Link>
                </Button>
              </div>
            ) : (
              children
            )}
          </AuthGuard>
        </main>
      </div>
    </div>
  )
}
