import i from "./index-extends.js";
import M from "./index-objectWithoutPropertiesLoose.js";
import * as n from "react";
import { isFragment as O } from "react-is";
import o from "./index-_virtual16.js";
import { clsx as L } from "./index-clsx.js";
import U from "./index-AccordionContext.js";
import _ from "./index-useSlot.js";
import d, { getAccordionUtilityClass as $ } from "./index-accordionClasses.js";
import { jsxs as F, jsx as g } from "react/jsx-runtime";
import { useDefaultProps as V } from "./index-DefaultPropsProvider.js";
import D from "./index-useControlled2.js";
import I from "./index-Collapse2.js";
import W from "./index-composeClasses.js";
import z from "./index-styled.js";
import H from "./index-Paper.js";
import J from "./index-chainPropTypes.js";
const K = ["children", "className", "defaultExpanded", "disabled", "disableGutters", "expanded", "onChange", "square", "slots", "slotProps", "TransitionComponent", "TransitionProps"], Q = (r) => {
  const {
    classes: e,
    square: s,
    expanded: a,
    disabled: l,
    disableGutters: p
  } = r;
  return W({
    root: ["root", !s && "rounded", a && "expanded", l && "disabled", !p && "gutters"],
    region: ["region"]
  }, $, e);
}, X = z(H, {
  name: "MuiAccordion",
  slot: "Root",
  overridesResolver: (r, e) => {
    const {
      ownerState: s
    } = r;
    return [{
      [`& .${d.region}`]: e.region
    }, e.root, !s.square && e.rounded, !s.disableGutters && e.gutters];
  }
})(({
  theme: r
}) => {
  const e = {
    duration: r.transitions.duration.shortest
  };
  return {
    position: "relative",
    transition: r.transitions.create(["margin"], e),
    overflowAnchor: "none",
    // Keep the same scrolling position
    "&::before": {
      position: "absolute",
      left: 0,
      top: -1,
      right: 0,
      height: 1,
      content: '""',
      opacity: 1,
      backgroundColor: (r.vars || r).palette.divider,
      transition: r.transitions.create(["opacity", "background-color"], e)
    },
    "&:first-of-type": {
      "&::before": {
        display: "none"
      }
    },
    [`&.${d.expanded}`]: {
      "&::before": {
        opacity: 0
      },
      "&:first-of-type": {
        marginTop: 0
      },
      "&:last-of-type": {
        marginBottom: 0
      },
      "& + &": {
        "&::before": {
          display: "none"
        }
      }
    },
    [`&.${d.disabled}`]: {
      backgroundColor: (r.vars || r).palette.action.disabledBackground
    }
  };
}, ({
  theme: r
}) => ({
  variants: [{
    props: (e) => !e.square,
    style: {
      borderRadius: 0,
      "&:first-of-type": {
        borderTopLeftRadius: (r.vars || r).shape.borderRadius,
        borderTopRightRadius: (r.vars || r).shape.borderRadius
      },
      "&:last-of-type": {
        borderBottomLeftRadius: (r.vars || r).shape.borderRadius,
        borderBottomRightRadius: (r.vars || r).shape.borderRadius,
        // Fix a rendering issue on Edge
        "@supports (-ms-ime-align: auto)": {
          borderBottomLeftRadius: 0,
          borderBottomRightRadius: 0
        }
      }
    }
  }, {
    props: (e) => !e.disableGutters,
    style: {
      [`&.${d.expanded}`]: {
        margin: "16px 0"
      }
    }
  }]
})), Y = /* @__PURE__ */ n.forwardRef(function(e, s) {
  const a = V({
    props: e,
    name: "MuiAccordion"
  }), {
    children: l,
    className: p,
    defaultExpanded: y = !1,
    disabled: c = !1,
    disableGutters: u = !1,
    expanded: P,
    onChange: f,
    square: x = !1,
    slots: R = {},
    slotProps: v = {},
    TransitionComponent: A,
    TransitionProps: w
  } = a, E = M(a, K), [t, h] = D({
    controlled: P,
    default: y,
    name: "Accordion",
    state: "expanded"
  }), C = n.useCallback((G) => {
    h(!t), f && f(G, !t);
  }, [t, f, h]), [m, ...j] = n.Children.toArray(l), q = n.useMemo(() => ({
    expanded: t,
    disabled: c,
    disableGutters: u,
    toggle: C
  }), [t, c, u, C]), b = i({}, a, {
    square: x,
    disabled: c,
    disableGutters: u,
    expanded: t
  }), T = Q(b), S = i({
    transition: A
  }, R), k = i({
    transition: w
  }, v), [N, B] = _("transition", {
    elementType: I,
    externalForwardedProps: {
      slots: S,
      slotProps: k
    },
    ownerState: b
  });
  return /* @__PURE__ */ F(X, i({
    className: L(T.root, p),
    ref: s,
    ownerState: b,
    square: x
  }, E, {
    children: [/* @__PURE__ */ g(U.Provider, {
      value: q,
      children: m
    }), /* @__PURE__ */ g(N, i({
      in: t,
      timeout: "auto"
    }, B, {
      children: /* @__PURE__ */ g("div", {
        "aria-labelledby": m.props.id,
        id: m.props["aria-controls"],
        role: "region",
        className: T.region,
        children: j
      })
    }))]
  }));
});
process.env.NODE_ENV !== "production" && (Y.propTypes = {
  // ┌────────────────────────────── Warning ──────────────────────────────┐
  // │ These PropTypes are generated from the TypeScript type definitions. │
  // │    To update them, edit the d.ts file and run `pnpm proptypes`.     │
  // └─────────────────────────────────────────────────────────────────────┘
  /**
   * The content of the component.
   */
  children: J(o.node.isRequired, (r) => {
    const e = n.Children.toArray(r.children)[0];
    return O(e) ? new Error("MUI: The Accordion doesn't accept a Fragment as a child. Consider providing an array instead.") : /* @__PURE__ */ n.isValidElement(e) ? null : new Error("MUI: Expected the first child of Accordion to be a valid element.");
  }),
  /**
   * Override or extend the styles applied to the component.
   */
  classes: o.object,
  /**
   * @ignore
   */
  className: o.string,
  /**
   * If `true`, expands the accordion by default.
   * @default false
   */
  defaultExpanded: o.bool,
  /**
   * If `true`, the component is disabled.
   * @default false
   */
  disabled: o.bool,
  /**
   * If `true`, it removes the margin between two expanded accordion items and the increase of height.
   * @default false
   */
  disableGutters: o.bool,
  /**
   * If `true`, expands the accordion, otherwise collapse it.
   * Setting this prop enables control over the accordion.
   */
  expanded: o.bool,
  /**
   * Callback fired when the expand/collapse state is changed.
   *
   * @param {React.SyntheticEvent} event The event source of the callback. **Warning**: This is a generic event not a change event.
   * @param {boolean} expanded The `expanded` state of the accordion.
   */
  onChange: o.func,
  /**
   * The props used for each slot inside.
   * @default {}
   */
  slotProps: o.shape({
    transition: o.oneOfType([o.func, o.object])
  }),
  /**
   * The components used for each slot inside.
   * @default {}
   */
  slots: o.shape({
    transition: o.elementType
  }),
  /**
   * If `true`, rounded corners are disabled.
   * @default false
   */
  square: o.bool,
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx: o.oneOfType([o.arrayOf(o.oneOfType([o.func, o.object, o.bool])), o.func, o.object]),
  /**
   * The component used for the transition.
   * [Follow this guide](/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
   * @deprecated Use `slots.transition` instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
   */
  TransitionComponent: o.elementType,
  /**
   * Props applied to the transition element.
   * By default, the element is based on this [`Transition`](https://reactcommunity.org/react-transition-group/transition/) component.
   * @deprecated Use `slotProps.transition` instead. This prop will be removed in v7. [How to migrate](/material-ui/migration/migrating-from-deprecated-apis/).
   */
  TransitionProps: o.object
});
export {
  Y as default
};
