import { Shield, ArrowLeft, Settings, RefreshCw } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Link, useLocation } from 'react-router-dom';
import { ThemeToggle } from '@/components/theme/ThemeToggle';
import { AuthButtons } from '@/components/auth/AuthButtons';
import { useUserRole } from '@/hooks/useUserRole';

export function AdminHeader({ onRefresh }: { onRefresh?: () => void }) {
  const { permissions } = useUserRole();
  const location = useLocation();
  
  const isSettingsPage = location.pathname === '/admin/settings';
  const backLink = isSettingsPage ? '/admin' : '/';
  const backText = isSettingsPage ? 'Back to Admin' : 'Back to ThrillWiki';
  const pageTitle = isSettingsPage ? 'Admin Settings' : 'Admin Dashboard';
  
  return (
    <header className="sticky top-0 z-50 w-full border-b border-border bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
      <div className="container flex h-16 items-center justify-between px-4">
        {/* Left Section - Navigation */}
        <div className="flex items-center gap-4">
          <Button variant="ghost" size="sm" asChild>
            <Link to={backLink} className="flex items-center gap-2">
              <ArrowLeft className="w-4 h-4" />
              <span className="hidden sm:inline">{backText}</span>
            </Link>
          </Button>
          
          <div className="h-6 w-px bg-border hidden sm:block" />
          
          <div className="flex items-center gap-2">
            <Shield className="w-6 h-6 text-primary" />
            <h1 className="text-lg font-semibold">
              <span className="sm:hidden">Admin</span>
              <span className="hidden sm:inline">{pageTitle}</span>
            </h1>
          </div>
        </div>

        {/* Right Section - Admin actions */}
        <div className="flex items-center gap-2">
          <Button 
            variant="ghost" 
            size="sm" 
            onClick={onRefresh}
            title="Refresh admin data"
          >
            <RefreshCw className="w-4 h-4" />
            <span className="hidden sm:ml-2 sm:inline">Refresh</span>
          </Button>
          {permissions?.role_level === 'superuser' && !isSettingsPage && (
            <Button variant="ghost" size="sm" asChild>
              <Link to="/admin/settings">
                <Settings className="w-4 h-4" />
                <span className="hidden sm:ml-2 sm:inline">Settings</span>
              </Link>
            </Button>
          )}
          <ThemeToggle />
          <AuthButtons />
        </div>
      </div>
    </header>
  );
}