"use client";
import { Slot } from '@radix-ui/react-slot';
import { cva } from 'class-variance-authority';
import * as React from 'react';
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';

function cn(...inputs) {
  return twMerge(clsx(inputs));
}
var SidebarContext = React.createContext(null);
function useSidebar() {
  const ctx = React.useContext(SidebarContext);
  if (!ctx) {
    throw new Error("useSidebar must be used inside <SidebarProvider>");
  }
  return ctx;
}
function SidebarProvider({
  open: openProp,
  defaultOpen = true,
  onOpenChange,
  children,
  className
}) {
  const [internalOpen, setInternalOpen] = React.useState(defaultOpen);
  const isControlled = openProp !== void 0;
  const open = isControlled ? openProp : internalOpen;
  const setOpen = React.useCallback(
    (next) => {
      if (!isControlled) {
        setInternalOpen(next);
      }
      onOpenChange?.(next);
    },
    [isControlled, onOpenChange]
  );
  const value = React.useMemo(() => ({ open, setOpen }), [open, setOpen]);
  return /* @__PURE__ */ jsx(SidebarContext.Provider, { value, children: /* @__PURE__ */ jsx(
    "div",
    {
      "data-state": open ? "open" : "closed",
      className: cn("flex min-h-screen w-full", className),
      children
    }
  ) });
}
SidebarProvider.displayName = "SidebarProvider";
var sidebarVariants = cva(
  cn(
    "flex h-full shrink-0 flex-col border-foreground/[0.08] border-r bg-background text-foreground",
    "transition-[width] duration-[var(--duration-normal,200ms)] ease-out"
  ),
  {
    variants: {
      side: {
        left: "border-r",
        right: "order-last border-l border-r-0"
      },
      state: {
        open: "w-64",
        closed: "w-0 overflow-hidden border-r-0"
      }
    },
    defaultVariants: {
      side: "left",
      state: "open"
    }
  }
);
var Sidebar = React.forwardRef(
  ({ className, side = "left", children, ...props }, ref) => {
    const { open } = useSidebar();
    return /* @__PURE__ */ jsx(
      "aside",
      {
        ref,
        "data-state": open ? "open" : "closed",
        "aria-hidden": !open || void 0,
        inert: !open,
        className: cn(sidebarVariants({ side, state: open ? "open" : "closed" }), className),
        ...props,
        children
      }
    );
  }
);
Sidebar.displayName = "Sidebar";
var SidebarTrigger = React.forwardRef(
  ({ asChild, className, onClick, "aria-label": ariaLabel, ...props }, ref) => {
    const { open, setOpen } = useSidebar();
    const Comp = asChild ? Slot : "button";
    const resolvedAriaLabel = ariaLabel ?? (asChild ? void 0 : open ? "Collapse sidebar" : "Expand sidebar");
    return /* @__PURE__ */ jsx(
      Comp,
      {
        ref,
        type: asChild ? void 0 : "button",
        "aria-label": resolvedAriaLabel,
        "aria-expanded": open,
        onClick: (event) => {
          onClick?.(event);
          if (!event.defaultPrevented) {
            setOpen(!open);
          }
        },
        className: cn(
          "inline-flex h-[var(--control-height-sm,2.25rem)] w-[var(--control-height-sm,2.25rem)] items-center justify-center rounded-md text-muted-foreground",
          "transition-all duration-[var(--duration-normal,200ms)] ease-out hover:bg-accent hover:text-accent-foreground",
          "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
          className
        ),
        ...props,
        children: asChild ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
          /* @__PURE__ */ jsxs(
            "svg",
            {
              xmlns: "http://www.w3.org/2000/svg",
              viewBox: "0 0 24 24",
              fill: "none",
              stroke: "currentColor",
              strokeWidth: "2",
              strokeLinecap: "round",
              strokeLinejoin: "round",
              className: "h-4 w-4",
              "aria-hidden": "true",
              children: [
                /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2", ry: "2" }),
                /* @__PURE__ */ jsx("line", { x1: "9", y1: "3", x2: "9", y2: "21" })
              ]
            }
          ),
          /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Toggle sidebar" })
        ] })
      }
    );
  }
);
SidebarTrigger.displayName = "SidebarTrigger";
var SidebarHeader = React.forwardRef(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx(
    "div",
    {
      ref,
      className: cn("flex items-center gap-[var(--gap-sm,0.5rem)] border-b border-b-foreground/[0.08] p-[var(--space-4,1rem)]", className),
      ...props
    }
  )
);
SidebarHeader.displayName = "SidebarHeader";
var SidebarContent = React.forwardRef(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx(
    "div",
    {
      ref,
      className: cn("flex-1 overflow-auto p-[var(--space-2,0.5rem)]", className),
      ...props
    }
  )
);
SidebarContent.displayName = "SidebarContent";
var SidebarFooter = React.forwardRef(
  ({ className, ...props }, ref) => /* @__PURE__ */ jsx(
    "div",
    {
      ref,
      className: cn("mt-auto border-t border-t-foreground/[0.08] p-[var(--space-4,1rem)]", className),
      ...props
    }
  )
);
SidebarFooter.displayName = "SidebarFooter";
var SidebarItem = React.forwardRef(
  ({ asChild, active, className, ...props }, ref) => {
    const Comp = asChild ? Slot : "button";
    return /* @__PURE__ */ jsx(
      Comp,
      {
        ref,
        type: asChild ? void 0 : "button",
        "aria-current": active ? "page" : void 0,
        "data-active": active ? "" : void 0,
        className: cn(
          "inline-flex w-full items-center gap-[var(--gap-sm,0.5rem)] rounded-md px-[var(--space-3,0.75rem)] py-[var(--space-2,0.5rem)] text-sm font-medium",
          "transition-all duration-[var(--duration-normal,200ms)] ease-out",
          "hover:bg-accent hover:text-accent-foreground",
          "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
          "data-[active]:bg-accent data-[active]:text-accent-foreground",
          className
        ),
        ...props
      }
    );
  }
);
SidebarItem.displayName = "SidebarItem";

export { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarItem, SidebarProvider, SidebarTrigger, useSidebar };
//# sourceMappingURL=sidebar.js.map
//# sourceMappingURL=sidebar.js.map