"use client";

import React from "react";
import { useChatWidgetStore } from "@/hooks/useChatWidgetStore";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { X, Minus, MessageSquare, Menu, Hash, Users } from "lucide-react";
import { cn } from "@/lib/utils";

interface ChatHeaderProps {
  presenceData: any;
  activeRoom?: any;
  onMinimize: () => void;
  onToggleRooms: () => void;
}

export function ChatHeader({ presenceData, activeRoom, onMinimize, onToggleRooms }: ChatHeaderProps) {
  const onlineCount = presenceData?.users?.length || 0;

  return (
    <div className="flex items-center justify-between p-3 border-b border-border bg-primary text-primary-foreground shadow-sm">
      <div className="flex items-center gap-3">
        <Button 
          variant="ghost" 
          size="icon" 
          onClick={onToggleRooms}
          aria-label="Kanäle anzeigen"
          className="h-8 w-8 text-primary-foreground hover:bg-primary-foreground/10 transition-colors"
        >
          <Menu className="h-5 w-5" />
        </Button>
        <div className="flex flex-col">
          <div className="flex items-center gap-2">
            {activeRoom?.type === 'direct' ? <Users className="h-3 w-3" /> : <Hash className="h-3 w-3" />}
            <h3 className="font-bold text-sm truncate max-w-[150px]">
              {activeRoom?.name || "Team Chat"}
            </h3>
            {onlineCount > 0 && (
              <Badge variant="secondary" className="h-4 px-1.5 text-xs font-bold bg-primary-foreground text-primary animate-pulse">
                {onlineCount} Online
              </Badge>
            )}
          </div>
          <p className="text-xs text-primary-foreground/70 font-medium">
            {activeRoom?.type === 'direct' ? 'Direct Message' : 'Group Channel'}
          </p>
        </div>
      </div>
      <div className="flex items-center gap-1">
        <Button
          variant="ghost"
          size="sm"
          onClick={(e) => {
            e.stopPropagation();
            onMinimize();
          }}
          aria-label="Chat minimieren"
          className="h-8 w-8 p-0 hover:bg-primary-foreground/10 text-primary-foreground transition-all active:scale-90"
        >
          <Minus className="h-4 w-4" />
        </Button>
      </div>
    </div>
  );
}
