import { ReactNode } from 'react';
import { PanelRight } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { useLayout } from './context';

function Toolbar({ children }: { children?: ReactNode }) {
  return (
    <div className="flex flex-wrap items-center justify-between gap-3.5 py-5">
      {children}
    </div>
  );
}

function ToolbarActions({ children }: { children?: ReactNode }) {
  return <div className="flex items-center gap-2.5">{children}</div>;
}

function ToolbarHeading ({ children }: { children: ReactNode }) {
  return <div className="flex flex-col justify-center gap-2">{children}</div>;
}

function ToolbarPageTitle ({ children }: { children?: string }) {
  return (
    <h1 className="text-base font-medium leading-none text-foreground">
      {children}
    </h1>
  );
};

function ToolbarDescription ({ children }: { children: ReactNode }) {
  return (
    <div className="flex items-center gap-2 text-sm font-normal text-muted-foreground">
      {children}
    </div>
  );
};

function ToolbarSidebarToggle() {
  const { isMobile, isSidebarOpen, sidebarToggle } = useLayout();

  if (isMobile || isSidebarOpen) {
    return null;
  }

  return (
    <Button 
      variant="ghost" 
      mode="icon" 
      onClick={sidebarToggle} 
      className="text-muted-foreground hover:text-foreground"
    >
      <PanelRight className="size-5 opacity-100" />
    </Button>
  );
}

export {
  Toolbar,
  ToolbarActions,
  ToolbarHeading,
  ToolbarPageTitle,
  ToolbarDescription,
  ToolbarSidebarToggle
};
