'use client'

import Link from 'next/link'
import ThemeToggle from './ThemeToggle'
import { signOut } from 'next-auth/react'
import { Button } from '@/components/ui/button'
import { LogOut, Zap } from 'lucide-react'

type Props = {
  isLoggedIn: boolean
}

export default function TopBar({ isLoggedIn }: Props) {
  async function onLogout() {
    await signOut({ callbackUrl: '/auth/login' })
  }

  return (
    <header className="sticky top-0 z-50 border-b bg-background/80 backdrop-blur-sm">
      <div className="mx-auto flex w-full max-w-7xl items-center justify-between px-4 py-2.5">
        {/* Logo */}
        <Link href="/" className="flex items-center gap-2">
          <div className="flex h-7 w-7 items-center justify-center rounded-lg bg-primary text-primary-foreground">
            <Zap className="size-4" />
          </div>
          <span className="text-base font-bold tracking-tight">NextGo</span>
        </Link>

        {/* Actions */}
        <nav className="flex items-center gap-1">
          <ThemeToggle />

          {isLoggedIn ? (
            <>
              <Button variant="ghost" size="sm" asChild>
                <Link href="/admin/users">Admin</Link>
              </Button>

              <Button type="button" onClick={onLogout} variant="destructive" size="sm">
                <LogOut className="size-4" />
                Çıkış
              </Button>
            </>
          ) : (
            <>
              <Button variant="ghost" size="sm" asChild>
                <Link href="/auth/login">Giriş</Link>
              </Button>
              <Button size="sm" asChild>
                <Link href="/auth/register">Kayıt Ol</Link>
              </Button>
            </>
          )}
        </nav>
      </div>
    </header>
  )
}

