import L from "./index-objectWithoutPropertiesLoose.js";
import m from "./index-extends.js";
import * as n from "react";
import e from "./index-_virtual16.js";
import { clsx as q } from "./index-clsx.js";
import U from "./index-styled.js";
import { isAdornedStart as w, isFilled as I } from "./index-utils8.js";
import V from "./index-FormControlContext.js";
import { getFormControlUtilityClasses as $ } from "./index-formControlClasses.js";
import { jsx as R } from "react/jsx-runtime";
import { useDefaultProps as k } from "./index-DefaultPropsProvider.js";
import C from "./index-isMuiElement2.js";
import B from "./index-capitalize.js";
import G from "./index-composeClasses.js";
const H = ["children", "className", "color", "component", "disabled", "error", "focused", "fullWidth", "hiddenLabel", "margin", "required", "size", "variant"], J = (o) => {
  const {
    classes: i,
    margin: d,
    fullWidth: l
  } = o, s = {
    root: ["root", d !== "none" && `margin${B(d)}`, l && "fullWidth"]
  };
  return G(s, $, i);
}, K = U("div", {
  name: "MuiFormControl",
  slot: "Root",
  overridesResolver: ({
    ownerState: o
  }, i) => m({}, i.root, i[`margin${B(o.margin)}`], o.fullWidth && i.fullWidth)
})(({
  ownerState: o
}) => m({
  display: "inline-flex",
  flexDirection: "column",
  position: "relative",
  // Reset fieldset default style.
  minWidth: 0,
  padding: 0,
  margin: 0,
  border: 0,
  verticalAlign: "top"
}, o.margin === "normal" && {
  marginTop: 16,
  marginBottom: 8
}, o.margin === "dense" && {
  marginTop: 8,
  marginBottom: 4
}, o.fullWidth && {
  width: "100%"
})), Q = /* @__PURE__ */ n.forwardRef(function(i, d) {
  const l = k({
    props: i,
    name: "MuiFormControl"
  }), {
    children: s,
    className: M,
    color: u = "primary",
    component: F = "div",
    disabled: a = !1,
    error: f = !1,
    focused: O,
    fullWidth: c = !1,
    hiddenLabel: p = !1,
    margin: P = "none",
    required: g = !1,
    size: h = "medium",
    variant: b = "outlined"
  } = l, _ = L(l, H), T = m({}, l, {
    color: u,
    component: F,
    disabled: a,
    error: f,
    fullWidth: c,
    hiddenLabel: p,
    margin: P,
    required: g,
    size: h,
    variant: b
  }), z = J(T), [x, A] = n.useState(() => {
    let r = !1;
    return s && n.Children.forEach(s, (t) => {
      if (!C(t, ["Input", "Select"]))
        return;
      const j = C(t, ["Select"]) ? t.props.input : t;
      j && w(j.props) && (r = !0);
    }), r;
  }), [S, W] = n.useState(() => {
    let r = !1;
    return s && n.Children.forEach(s, (t) => {
      C(t, ["Input", "Select"]) && (I(t.props, !0) || I(t.props.inputProps, !0)) && (r = !0);
    }), r;
  }), [E, v] = n.useState(!1);
  a && E && v(!1);
  const N = O !== void 0 && !a ? O : E;
  let y;
  if (process.env.NODE_ENV !== "production") {
    const r = n.useRef(!1);
    y = () => (r.current, r.current = !0, () => {
      r.current = !1;
    });
  }
  const D = n.useMemo(() => ({
    adornedStart: x,
    setAdornedStart: A,
    color: u,
    disabled: a,
    error: f,
    filled: S,
    focused: N,
    fullWidth: c,
    hiddenLabel: p,
    size: h,
    onBlur: () => {
      v(!1);
    },
    onEmpty: () => {
      W(!1);
    },
    onFilled: () => {
      W(!0);
    },
    onFocus: () => {
      v(!0);
    },
    registerEffect: y,
    required: g,
    variant: b
  }), [x, u, a, f, S, N, c, p, y, g, h, b]);
  return /* @__PURE__ */ R(V.Provider, {
    value: D,
    children: /* @__PURE__ */ R(K, m({
      as: F,
      ownerState: T,
      className: q(z.root, M),
      ref: d
    }, _, {
      children: s
    }))
  });
});
process.env.NODE_ENV !== "production" && (Q.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: e.node,
  /**
   * Override or extend the styles applied to the component.
   */
  classes: e.object,
  /**
   * @ignore
   */
  className: e.string,
  /**
   * The color of the component.
   * It supports both default and custom theme colors, which can be added as shown in the
   * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
   * @default 'primary'
   */
  color: e.oneOfType([e.oneOf(["primary", "secondary", "error", "info", "success", "warning"]), e.string]),
  /**
   * The component used for the root node.
   * Either a string to use a HTML element or a component.
   */
  component: e.elementType,
  /**
   * If `true`, the label, input and helper text should be displayed in a disabled state.
   * @default false
   */
  disabled: e.bool,
  /**
   * If `true`, the label is displayed in an error state.
   * @default false
   */
  error: e.bool,
  /**
   * If `true`, the component is displayed in focused state.
   */
  focused: e.bool,
  /**
   * If `true`, the component will take up the full width of its container.
   * @default false
   */
  fullWidth: e.bool,
  /**
   * If `true`, the label is hidden.
   * This is used to increase density for a `FilledInput`.
   * Be sure to add `aria-label` to the `input` element.
   * @default false
   */
  hiddenLabel: e.bool,
  /**
   * If `dense` or `normal`, will adjust vertical spacing of this and contained components.
   * @default 'none'
   */
  margin: e.oneOf(["dense", "none", "normal"]),
  /**
   * If `true`, the label will indicate that the `input` is required.
   * @default false
   */
  required: e.bool,
  /**
   * The size of the component.
   * @default 'medium'
   */
  size: e.oneOfType([e.oneOf(["medium", "small"]), e.string]),
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx: e.oneOfType([e.arrayOf(e.oneOfType([e.func, e.object, e.bool])), e.func, e.object]),
  /**
   * The variant to use.
   * @default 'outlined'
   */
  variant: e.oneOf(["filled", "outlined", "standard"])
});
export {
  Q as default
};
