import "../Accordion.css";
import { jsx } from "react/jsx-runtime";
import { createElement } from "react";
import { Collapse } from "antd";
import { ConditionalWrapper } from "./internal/ConditionalWrapper.js";
import { useTheme } from "./Theme/UI.js";
import "./Theme/themeUtils.js";
import "./Theme/themes.js";
const base = "Accordion_base_a76e3";
const css = {
  base
};
const AccordionGroup = ({
  exclusive,
  children,
  openKey,
  defaultOpenKey
}) => {
  const activeProp = openKey !== void 0 ? { activeKey: openKey } : {};
  const defaultActiveKey = defaultOpenKey ? defaultOpenKey : exclusive ? [] : void 0;
  return /* @__PURE__ */ jsx(Collapse, { accordion: exclusive, ...activeProp, defaultActiveKey, children });
};
const Accordion = ({
  title,
  children,
  open,
  defaultOpen,
  mountChildren = "once-on-open",
  ...otherProps
}) => {
  const {
    themeSettings: { className: themeClass }
  } = useTheme();
  const inGroup = "panelKey" in otherProps;
  const key = -1;
  const wrapper = (c) => {
    let collapseProps = {};
    if (defaultOpen !== void 0) {
      collapseProps = { defaultActiveKey: defaultOpen ? key : "" };
    }
    if (open !== void 0) {
      collapseProps = { activeKey: open ? key : "" };
    }
    return /* @__PURE__ */ jsx(Collapse, { ...collapseProps, children: c });
  };
  let panelProps = {};
  switch (mountChildren) {
    case "immediately": {
      panelProps = { forceRender: true };
      break;
    }
    case "on-open": {
      panelProps = { destroyInactivePanel: true };
      break;
    }
    case "once-on-open":
    default: {
      panelProps = {};
    }
  }
  return /* @__PURE__ */ jsx(ConditionalWrapper, { condition: !inGroup, wrapper, children: /* @__PURE__ */ createElement(
    Collapse.Panel,
    {
      className: [css.base, themeClass].join(" "),
      header: title,
      ...otherProps,
      ...panelProps,
      key
    },
    children
  ) });
};
Accordion.Group = AccordionGroup;
export {
  Accordion as default
};
