// src/components/layout-and-navigation/Expandable.tsx
import { forwardRef, useEffect, useState } from "react";
import { ChevronDown, ChevronUp } from "lucide-react";
import clsx from "clsx";

// src/util/noop.ts
var noop = () => void 0;

// src/components/layout-and-navigation/Expandable.tsx
import { jsx, jsxs } from "react/jsx-runtime";
var DefaultIcon = (expanded) => expanded ? /* @__PURE__ */ jsx(ChevronUp, { className: "min-w-4 w-4" }) : /* @__PURE__ */ jsx(ChevronDown, { className: "min-w-4 w-4" });
var Expandable = forwardRef(function Expandable2({
  children,
  label,
  icon,
  isExpanded = false,
  onChange = noop,
  clickOnlyOnHeader = true,
  disabled = false,
  className,
  headerClassName,
  contentClassName
}, ref) {
  icon ??= DefaultIcon;
  return /* @__PURE__ */ jsxs(
    "div",
    {
      ref,
      className: clsx("col gap-y-0 bg-surface text-on-surface group rounded-lg shadow-sm", { "cursor-pointer": !clickOnlyOnHeader && !disabled }, className),
      onClick: () => !clickOnlyOnHeader && !disabled && onChange(!isExpanded),
      children: [
        /* @__PURE__ */ jsxs(
          "div",
          {
            className: clsx(
              "row py-2 px-4 rounded-lg justify-between items-center bg-surface text-on-surface select-none",
              {
                "group-hover:brightness-95": !isExpanded,
                "hover:brightness-95": isExpanded && !disabled,
                "cursor-pointer": clickOnlyOnHeader && !disabled
              },
              headerClassName
            ),
            onClick: () => clickOnlyOnHeader && !disabled && onChange(!isExpanded),
            children: [
              label,
              icon(isExpanded)
            ]
          }
        ),
        isExpanded && /* @__PURE__ */ jsx("div", { className: clsx("col px-4 pb-2", contentClassName), children })
      ]
    }
  );
});
var ExpandableUncontrolled = forwardRef(function ExpandableUncontrolled2({
  isExpanded,
  onChange = noop,
  ...props
}, ref) {
  const [usedIsExpanded, setUsedIsExpanded] = useState(isExpanded);
  useEffect(() => {
    setUsedIsExpanded(isExpanded);
  }, [isExpanded]);
  return /* @__PURE__ */ jsx(
    Expandable,
    {
      ...props,
      ref,
      isExpanded: usedIsExpanded,
      onChange: (value) => {
        onChange(value);
        setUsedIsExpanded(value);
      }
    }
  );
});
export {
  Expandable,
  ExpandableUncontrolled
};
//# sourceMappingURL=Expandable.mjs.map