import { jsx as P, jsxs as D, Fragment as j } from "react/jsx-runtime";
import { useSlotRecipe as H } from "@chakra-ui/react/styled-system";
import { Check as N, Remove as L } from "@commercetools/nimbus-icons";
import { e as T } from "./extract-style-props-CMyV-es-.es.js";
import { createSlotRecipeContext as W } from "@chakra-ui/react";
import { a as z } from "./RSPContexts-DLgb84PF.es.js";
import { $ as A, c as G, d as J, f as S, a as K } from "./utils-CrjF8U_E.es.js";
import { $ as Q } from "./Form-CXcEMuBf.es.js";
import { $ as V } from "./mergeProps-B-cqsBhL.es.js";
import { $ as U } from "./filterDOMProps-Cxz9cAAv.es.js";
import { $ as X } from "./useObjectRef-CaJ5pgjX.es.js";
import R, { useEffect as k, useMemo as B, useRef as Y, forwardRef as Z, useContext as ee, createContext as ie } from "react";
import { $ as g, a as ae, b as O, c as de } from "./useFormValidation-Cx9rG8-b.es.js";
import { $ as te } from "./usePress-UxAvyvOO.es.js";
import { $ as ne } from "./useToggle-DPaFYvr8.es.js";
import { $ as q } from "./useToggleState-DWm4nWJh.es.js";
import { $ as le } from "./useFocusRing-CZQUsztf.es.js";
import { $ as oe } from "./useHover-BiPYlZr_.es.js";
import { $ as re } from "./VisuallyHidden-BW_C1pFq.es.js";
function _(i, e, a) {
  let l = g({
    ...i,
    value: e.isSelected
  }), { isInvalid: m, validationErrors: v, validationDetails: c } = l.displayValidation, { labelProps: f, inputProps: r, isSelected: d, isPressed: t, isDisabled: u, isReadOnly: $ } = ne({
    ...i,
    isInvalid: m
  }, e, a);
  ae(i, l, a);
  let { isIndeterminate: b, isRequired: o, validationBehavior: s = "aria" } = i;
  k(() => {
    a.current && (a.current.indeterminate = !!b);
  });
  let { pressProps: h } = te({
    isDisabled: u || $,
    onPress() {
      let { [O]: n } = i, { commitValidation: x } = n || l;
      x();
    }
  });
  return {
    labelProps: V(f, h, B(() => ({
      // Prevent label from being focused when mouse down on it.
      // Note, this does not prevent the input from being focused in the `click` event.
      onMouseDown: (n) => n.preventDefault()
    }), [])),
    inputProps: {
      ...r,
      checked: d,
      "aria-required": o && s === "aria" || void 0,
      required: o && s === "native"
    },
    isSelected: d,
    isPressed: t,
    isDisabled: u,
    isReadOnly: $,
    isInvalid: m,
    validationErrors: v,
    validationDetails: c
  };
}
const se = /* @__PURE__ */ new WeakMap();
function ce(i, e, a) {
  const l = q({
    isReadOnly: i.isReadOnly || e.isReadOnly,
    isSelected: e.isSelected(i.value),
    defaultSelected: e.defaultValue.includes(i.value),
    onChange(n) {
      n ? e.addValue(i.value) : e.removeValue(i.value), i.onChange && i.onChange(n);
    }
  });
  let { name: m, form: v, descriptionId: c, errorMessageId: f, validationBehavior: r } = se.get(e);
  var d;
  r = (d = i.validationBehavior) !== null && d !== void 0 ? d : r;
  let { realtimeValidation: t } = g({
    ...i,
    value: l.isSelected,
    // Server validation is handled at the group level.
    name: void 0,
    validationBehavior: "aria"
  }), u = Y(de), $ = () => {
    e.setInvalid(i.value, t.isInvalid ? t : u.current);
  };
  k($);
  let b = e.realtimeValidation.isInvalid ? e.realtimeValidation : t, o = r === "native" ? e.displayValidation : b;
  var s;
  let h = _({
    ...i,
    isReadOnly: i.isReadOnly || e.isReadOnly,
    isDisabled: i.isDisabled || e.isDisabled,
    name: i.name || m,
    form: i.form || v,
    isRequired: (s = i.isRequired) !== null && s !== void 0 ? s : e.isRequired,
    validationBehavior: r,
    [O]: {
      realtimeValidation: b,
      displayValidation: o,
      resetValidation: e.resetValidation,
      commitValidation: e.commitValidation,
      updateValidation(n) {
        u.current = n, $();
      }
    }
  }, l, a);
  return {
    ...h,
    inputProps: {
      ...h.inputProps,
      "aria-describedby": [
        i["aria-describedby"],
        e.isInvalid ? f : null,
        c
      ].filter(Boolean).join(" ") || void 0
    }
  };
}
const fe = /* @__PURE__ */ ie(null), ue = /* @__PURE__ */ Z(function(e, a) {
  let { inputRef: l = null, ...m } = e;
  [e, a] = A(m, a, z);
  let { validationBehavior: v } = G(Q) || {};
  var c, f;
  let r = (f = (c = e.validationBehavior) !== null && c !== void 0 ? c : v) !== null && f !== void 0 ? f : "native", d = ee(fe), t = X(B(() => J(l, e.inputRef !== void 0 ? e.inputRef : null), [
    l,
    e.inputRef
  ])), { labelProps: u, inputProps: $, isSelected: b, isDisabled: o, isReadOnly: s, isPressed: h, isInvalid: n } = d ? ce({
    ...S(e),
    // Value is optional for standalone checkboxes, but required for CheckboxGroup items;
    // it's passed explicitly here to avoid typescript error (requires ignore).
    // @ts-ignore
    value: e.value,
    // ReactNode type doesn't allow function children.
    children: typeof e.children == "function" ? !0 : e.children
  }, d, t) : _({
    ...S(e),
    children: typeof e.children == "function" ? !0 : e.children,
    validationBehavior: r
  }, q(e), t), { isFocused: x, isFocusVisible: y, focusProps: F } = le(), w = o || s, { hoverProps: M, isHovered: I } = oe({
    ...e,
    isDisabled: w
  }), C = K({
    ...e,
    defaultClassName: "react-aria-Checkbox",
    values: {
      isSelected: b,
      isIndeterminate: e.isIndeterminate || !1,
      isPressed: h,
      isHovered: I,
      isFocused: x,
      isFocusVisible: y,
      isDisabled: o,
      isReadOnly: s,
      isInvalid: n,
      isRequired: e.isRequired || !1
    }
  }), p = U(e, {
    global: !0
  });
  return delete p.id, delete p.onClick, /* @__PURE__ */ R.createElement("label", {
    ...V(p, u, M, C),
    ref: a,
    slot: e.slot || void 0,
    "data-selected": b || void 0,
    "data-indeterminate": e.isIndeterminate || void 0,
    "data-pressed": h || void 0,
    "data-hovered": I || void 0,
    "data-focused": x || void 0,
    "data-focus-visible": y || void 0,
    "data-disabled": o || void 0,
    "data-readonly": s || void 0,
    "data-invalid": n || void 0,
    "data-required": e.isRequired || void 0
  }, /* @__PURE__ */ R.createElement(re, {
    elementType: "span"
  }, /* @__PURE__ */ R.createElement("input", {
    ...V($, F),
    ref: t
  })), C.children);
}), { withProvider: $e, withContext: E } = /* @__PURE__ */ W({
  key: "nimbusCheckbox"
}), be = /* @__PURE__ */ $e(ue, "root"), me = /* @__PURE__ */ E("span", "label"), ve = /* @__PURE__ */ E(
  "span",
  "indicator"
), he = (i) => {
  const { ref: e, children: a, ...l } = i, m = H({ key: "nimbusCheckbox" }), [v, c] = m.splitVariantProps(l), [f, r] = T(c);
  return /* @__PURE__ */ P(
    be,
    {
      ref: e,
      "data-slot": "root",
      ...r,
      ...v,
      ...f,
      children: ({
        isSelected: d,
        isIndeterminate: t,
        isInvalid: u,
        isDisabled: $,
        isFocused: b
      }) => {
        const o = {
          "data-selected": d,
          "data-indeterminate": t,
          "data-invalid": u,
          "data-disabled": $,
          "data-focus": b || void 0
        };
        return /* @__PURE__ */ D(j, { children: [
          /* @__PURE__ */ D(ve, { "data-slot": "indicator", ...o, children: [
            d && /* @__PURE__ */ P(N, {}),
            t && /* @__PURE__ */ P(L, {})
          ] }),
          a && /* @__PURE__ */ P(me, { "data-slot": "label", ...o, children: a })
        ] });
      }
    }
  );
};
he.displayName = "Checkbox";
export {
  he as C
};
//# sourceMappingURL=checkbox-CJUPY60M.es.js.map
