"use client";

import * as React from "react";
import { Bell, Building2, Plus } from "lucide-react";
import Link from "next/link";

import { ModeToggle } from "@/components/mode-toggle";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Separator } from "@/components/ui/separator";
import { SidebarTrigger } from "@/components/ui/sidebar";

import type { ShellCompany } from "@/app/(dashboard)/dashboard-shell";

export function SiteHeader({
  company,
  unreadCount = 0,
}: {
  company?: ShellCompany;
  unreadCount?: number;
}) {
  const showNewJobCta = company?.kind === "clinic";

  return (
    <header className="flex h-(--header-height) shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear group-has-data-[collapsible=icon]/sidebar-wrapper:h-(--header-height)">
      <div className="flex w-full items-center gap-1 px-4 py-3 lg:gap-2 lg:px-6">
        <SidebarTrigger className="-ml-1" />
        <Separator
          orientation="vertical"
          className="mx-2 data-[orientation=vertical]:h-4"
        />

        {company && (
          <div className="text-muted-foreground hidden items-center gap-1.5 text-sm md:flex">
            <Building2 className="size-3.5" />
            <span className="max-w-[260px] truncate">{company.name}</span>
          </div>
        )}

        <div className="ml-auto flex items-center gap-2">
          {showNewJobCta && (
            <Button asChild size="sm">
              <Link href="/jobs/new">
                <Plus className="size-4" />
                Yeni İş Yayınla
              </Link>
            </Button>
          )}
          <Button asChild variant="ghost" size="icon" className="relative">
            <Link href="/notifications" aria-label="Bildirimler">
              <Bell className="size-4" />
              {unreadCount > 0 && (
                <Badge
                  variant="destructive"
                  className="absolute -right-1 -top-1 size-4 min-w-4 justify-center rounded-full p-0 text-[10px]"
                >
                  {unreadCount > 99 ? "99+" : unreadCount}
                </Badge>
              )}
            </Link>
          </Button>
          <ModeToggle />
        </div>
      </div>
    </header>
  );
}
