"use client";

import { cn } from "@/lib/utils";
import { useSidebarStore } from "@/lib/stores/sidebar-store";

import { SidebarHeader } from "./sidebar-header";
import { SidebarNav } from "./sidebar-nav";
import { SidebarToggle } from "./sidebar-toggle";

export function Sidebar({ onOpenSearch }: { onOpenSearch?: () => void }) {
  const collapsed = useSidebarStore((s) => s.isCollapsed);

  return (
    <aside
      className={cn(
        "flex h-full shrink-0 flex-col overflow-hidden border-r border-sidebar-border bg-sidebar text-sidebar-foreground transition-[width] duration-200 ease-out",
        collapsed ? "w-12" : "w-[240px]",
      )}
    >
      <SidebarHeader collapsed={collapsed} />
      <SidebarNav collapsed={collapsed} onOpenSearch={onOpenSearch} />
      <div className="mt-auto shrink-0 border-t border-sidebar-border px-1 py-2">
        <div className={cn("flex", collapsed ? "justify-center" : "justify-end")}>
          <SidebarToggle />
        </div>
      </div>
    </aside>
  );
}
