// src/components/layout-and-navigation/Expandable.tsx
import { forwardRef, useCallback, useEffect, useState } from "react";
import { ChevronDown } 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 ExpansionIcon = ({ isExpanded, className }) => {
  return /* @__PURE__ */ jsx(
    ChevronDown,
    {
      className: clsx(
        "min-w-6 w-6 min-h-6 h-6 transition-transform duration-200 ease-in-out",
        { "rotate-180": isExpanded },
        className
      )
    }
  );
};
var Expandable = forwardRef(function Expandable2({
  children,
  label,
  icon,
  isExpanded = false,
  onChange = noop,
  clickOnlyOnHeader = true,
  disabled = false,
  className,
  headerClassName,
  contentClassName,
  contentExpandedClassName
}, ref) {
  const defaultIcon = useCallback((expanded) => /* @__PURE__ */ jsx(ExpansionIcon, { isExpanded: expanded }), []);
  icon ??= defaultIcon;
  return /* @__PURE__ */ jsxs(
    "div",
    {
      ref,
      className: clsx("flex-col-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(
              "flex-row-2 py-2 px-4 rounded-lg justify-between items-center bg-surface text-on-surface select-none",
              {
                "group-hover:brightness-97": !isExpanded,
                "hover:brightness-97": isExpanded && !disabled,
                "cursor-pointer": clickOnlyOnHeader && !disabled
              },
              headerClassName
            ),
            onClick: () => clickOnlyOnHeader && !disabled && onChange(!isExpanded),
            children: [
              label,
              icon(isExpanded)
            ]
          }
        ),
        /* @__PURE__ */ jsx(
          "div",
          {
            className: clsx(
              "flex-col-2 px-4 transition-all duration-300 ease-in-out",
              {
                [clsx("max-h-96 opacity-100 pb-2 overflow-y-auto", contentExpandedClassName)]: isExpanded,
                "max-h-0 opacity-0 overflow-hidden": !isExpanded
              },
              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,
  ExpansionIcon
};
//# sourceMappingURL=Expandable.mjs.map