import w from "./index-extends.js";
import Me from "./index-objectWithoutPropertiesLoose.js";
import * as t from "react";
import e from "./index-_virtual16.js";
import { clsx as ge } from "./index-clsx.js";
import Ce from "./index-styled.js";
import Be from "./index-TouchRipple.js";
import De, { getButtonBaseUtilityClass as xe } from "./index-buttonBaseClasses.js";
import { jsxs as ke, jsx as Ve } from "react/jsx-runtime";
import { useDefaultProps as Ee } from "./index-DefaultPropsProvider.js";
import _ from "./index-useForkRef.js";
import we from "./index-useIsFocusVisible2.js";
import M from "./index-useEventCallback2.js";
import Fe from "./index-composeClasses.js";
import Le from "./index-elementTypeAcceptingRef.js";
import Ne from "./index-refType.js";
const Se = ["action", "centerRipple", "children", "className", "component", "disabled", "disableRipple", "disableTouchRipple", "focusRipple", "focusVisibleClassName", "LinkComponent", "onBlur", "onClick", "onContextMenu", "onDragLeave", "onFocus", "onFocusVisible", "onKeyDown", "onKeyUp", "onMouseDown", "onMouseLeave", "onMouseUp", "onTouchEnd", "onTouchMove", "onTouchStart", "tabIndex", "TouchRippleProps", "touchRippleRef", "type"], Ue = (g) => {
  const {
    disabled: c,
    focusVisible: b,
    focusVisibleClassName: i,
    classes: C
  } = g, m = Fe({
    root: ["root", c && "disabled", b && "focusVisible"]
  }, xe, C);
  return b && i && (m.root += ` ${i}`), m;
}, Pe = Ce("button", {
  name: "MuiButtonBase",
  slot: "Root",
  overridesResolver: (g, c) => c.root
})({
  display: "inline-flex",
  alignItems: "center",
  justifyContent: "center",
  position: "relative",
  boxSizing: "border-box",
  WebkitTapHighlightColor: "transparent",
  backgroundColor: "transparent",
  // Reset default value
  // We disable the focus ring for mouse, touch and keyboard users.
  outline: 0,
  border: 0,
  margin: 0,
  // Remove the margin in Safari
  borderRadius: 0,
  padding: 0,
  // Remove the padding in Firefox
  cursor: "pointer",
  userSelect: "none",
  verticalAlign: "middle",
  MozAppearance: "none",
  // Reset
  WebkitAppearance: "none",
  // Reset
  textDecoration: "none",
  // So we take precedent over the style of a native <a /> element.
  color: "inherit",
  "&::-moz-focus-inner": {
    borderStyle: "none"
    // Remove Firefox dotted outline.
  },
  [`&.${De.disabled}`]: {
    pointerEvents: "none",
    // Disable link interactions
    cursor: "default"
  },
  "@media print": {
    colorAdjust: "exact"
  }
}), je = /* @__PURE__ */ t.forwardRef(function(c, b) {
  const i = Ee({
    props: c,
    name: "MuiButtonBase"
  }), {
    action: C,
    centerRipple: B = !1,
    children: m,
    className: q,
    component: h = "button",
    disabled: r = !1,
    disableRipple: R = !1,
    disableTouchRipple: F = !1,
    focusRipple: a = !1,
    LinkComponent: z = "a",
    onBlur: L,
    onClick: l,
    onContextMenu: H,
    onDragLeave: W,
    onFocus: N,
    onFocusVisible: S,
    onKeyDown: U,
    onKeyUp: P,
    onMouseDown: $,
    onMouseLeave: j,
    onMouseUp: G,
    onTouchEnd: J,
    onTouchMove: Q,
    onTouchStart: X,
    tabIndex: K = 0,
    TouchRippleProps: Y,
    touchRippleRef: Z,
    type: D
  } = i, p = Me(i, Se), f = t.useRef(null), n = t.useRef(null), ee = _(n, Z), {
    isFocusVisibleRef: I,
    onFocus: oe,
    onBlur: ne,
    ref: te
  } = we(), [u, y] = t.useState(!1);
  r && u && y(!1), t.useImperativeHandle(C, () => ({
    focusVisible: () => {
      y(!0), f.current.focus();
    }
  }), []);
  const [x, se] = t.useState(!1);
  t.useEffect(() => {
    se(!0);
  }, []);
  const k = x && !R && !r;
  t.useEffect(() => {
    u && a && !R && x && n.current.pulsate();
  }, [R, a, u, x]);
  function s(o, A, Te = F) {
    return M((v) => (A && A(v), !Te && n.current && n.current[o](v), !0));
  }
  const re = s("start", $), ue = s("stop", H), ie = s("stop", W), ce = s("stop", G), ae = s("stop", (o) => {
    u && o.preventDefault(), j && j(o);
  }), le = s("start", X), pe = s("stop", J), fe = s("stop", Q), de = s("stop", (o) => {
    ne(o), I.current === !1 && y(!1), L && L(o);
  }, !1), be = M((o) => {
    f.current || (f.current = o.currentTarget), oe(o), I.current === !0 && (y(!0), S && S(o)), N && N(o);
  }), V = () => {
    const o = f.current;
    return h && h !== "button" && !(o.tagName === "A" && o.href);
  }, E = t.useRef(!1), me = M((o) => {
    a && !E.current && u && n.current && o.key === " " && (E.current = !0, n.current.stop(o, () => {
      n.current.start(o);
    })), o.target === o.currentTarget && V() && o.key === " " && o.preventDefault(), U && U(o), o.target === o.currentTarget && V() && o.key === "Enter" && !r && (o.preventDefault(), l && l(o));
  }), he = M((o) => {
    a && o.key === " " && n.current && u && !o.defaultPrevented && (E.current = !1, n.current.stop(o, () => {
      n.current.pulsate(o);
    })), P && P(o), l && o.target === o.currentTarget && V() && o.key === " " && !o.defaultPrevented && l(o);
  });
  let T = h;
  T === "button" && (p.href || p.to) && (T = z);
  const d = {};
  T === "button" ? (d.type = D === void 0 ? "button" : D, d.disabled = r) : (!p.href && !p.to && (d.role = "button"), r && (d["aria-disabled"] = r));
  const Re = _(b, te, f);
  process.env.NODE_ENV !== "production" && t.useEffect(() => {
    k && n.current;
  }, [k]);
  const O = w({}, i, {
    centerRipple: B,
    component: h,
    disabled: r,
    disableRipple: R,
    disableTouchRipple: F,
    focusRipple: a,
    tabIndex: K,
    focusVisible: u
  }), ye = Ue(O);
  return /* @__PURE__ */ ke(Pe, w({
    as: T,
    className: ge(ye.root, q),
    ownerState: O,
    onBlur: de,
    onClick: l,
    onContextMenu: ue,
    onFocus: be,
    onKeyDown: me,
    onKeyUp: he,
    onMouseDown: re,
    onMouseLeave: ae,
    onMouseUp: ce,
    onDragLeave: ie,
    onTouchEnd: pe,
    onTouchMove: fe,
    onTouchStart: le,
    ref: Re,
    tabIndex: r ? -1 : K,
    type: D
  }, d, p, {
    children: [m, k ? (
      /* TouchRipple is only needed client-side, x2 boost on the server. */
      /* @__PURE__ */ Ve(Be, w({
        ref: ee,
        center: B
      }, Y))
    ) : null]
  }));
});
process.env.NODE_ENV !== "production" && (je.propTypes = {
  // ┌────────────────────────────── Warning ──────────────────────────────┐
  // │ These PropTypes are generated from the TypeScript type definitions. │
  // │    To update them, edit the d.ts file and run `pnpm proptypes`.     │
  // └─────────────────────────────────────────────────────────────────────┘
  /**
   * A ref for imperative actions.
   * It currently only supports `focusVisible()` action.
   */
  action: Ne,
  /**
   * If `true`, the ripples are centered.
   * They won't start at the cursor interaction position.
   * @default false
   */
  centerRipple: e.bool,
  /**
   * 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 component used for the root node.
   * Either a string to use a HTML element or a component.
   */
  component: Le,
  /**
   * If `true`, the component is disabled.
   * @default false
   */
  disabled: e.bool,
  /**
   * If `true`, the ripple effect is disabled.
   *
   * ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure
   * to highlight the element by applying separate styles with the `.Mui-focusVisible` class.
   * @default false
   */
  disableRipple: e.bool,
  /**
   * If `true`, the touch ripple effect is disabled.
   * @default false
   */
  disableTouchRipple: e.bool,
  /**
   * If `true`, the base button will have a keyboard focus ripple.
   * @default false
   */
  focusRipple: e.bool,
  /**
   * This prop can help identify which element has keyboard focus.
   * The class name will be applied when the element gains the focus through keyboard interaction.
   * It's a polyfill for the [CSS :focus-visible selector](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo).
   * The rationale for using this feature [is explained here](https://github.com/WICG/focus-visible/blob/HEAD/explainer.md).
   * A [polyfill can be used](https://github.com/WICG/focus-visible) to apply a `focus-visible` class to other components
   * if needed.
   */
  focusVisibleClassName: e.string,
  /**
   * @ignore
   */
  href: e.any,
  /**
   * The component used to render a link when the `href` prop is provided.
   * @default 'a'
   */
  LinkComponent: e.elementType,
  /**
   * @ignore
   */
  onBlur: e.func,
  /**
   * @ignore
   */
  onClick: e.func,
  /**
   * @ignore
   */
  onContextMenu: e.func,
  /**
   * @ignore
   */
  onDragLeave: e.func,
  /**
   * @ignore
   */
  onFocus: e.func,
  /**
   * Callback fired when the component is focused with a keyboard.
   * We trigger a `onFocus` callback too.
   */
  onFocusVisible: e.func,
  /**
   * @ignore
   */
  onKeyDown: e.func,
  /**
   * @ignore
   */
  onKeyUp: e.func,
  /**
   * @ignore
   */
  onMouseDown: e.func,
  /**
   * @ignore
   */
  onMouseLeave: e.func,
  /**
   * @ignore
   */
  onMouseUp: e.func,
  /**
   * @ignore
   */
  onTouchEnd: e.func,
  /**
   * @ignore
   */
  onTouchMove: e.func,
  /**
   * @ignore
   */
  onTouchStart: e.func,
  /**
   * 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]),
  /**
   * @default 0
   */
  tabIndex: e.number,
  /**
   * Props applied to the `TouchRipple` element.
   */
  TouchRippleProps: e.object,
  /**
   * A ref that points to the `TouchRipple` element.
   */
  touchRippleRef: e.oneOfType([e.func, e.shape({
    current: e.shape({
      pulsate: e.func.isRequired,
      start: e.func.isRequired,
      stop: e.func.isRequired
    })
  })]),
  /**
   * @ignore
   */
  type: e.oneOfType([e.oneOf(["button", "reset", "submit"]), e.string])
});
export {
  Pe as ButtonBaseRoot,
  je as default
};
