"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
require("react");
const getSize = require("../../core/utils/get-size/get-size.cjs");
const createVarsResolver = require("../../core/styles-api/create-vars-resolver/create-vars-resolver.cjs");
require("clsx");
const parseThemeColor = require("../../core/MantineProvider/color-functions/parse-theme-color/parse-theme-color.cjs");
const getThemeColor = require("../../core/MantineProvider/color-functions/get-theme-color/get-theme-color.cjs");
const getContrastColor = require("../../core/MantineProvider/color-functions/get-contrast-color/get-contrast-color.cjs");
const getAutoContrastValue = require("../../core/MantineProvider/color-functions/get-auto-contrast-value/get-auto-contrast-value.cjs");
const useProps = require("../../core/MantineProvider/use-props/use-props.cjs");
const useStyles = require("../../core/styles-api/use-styles/use-styles.cjs");
const extractStyleProps = require("../../core/Box/style-props/extract-style-props/extract-style-props.cjs");
const Box = require("../../core/Box/Box.cjs");
const factory = require("../../core/factory/factory.cjs");
const InlineInput = require("../InlineInput/InlineInput.cjs");
const CheckboxCard = require("./CheckboxCard/CheckboxCard.cjs");
const CheckboxGroup_context = require("./CheckboxGroup.context.cjs");
const CheckboxGroup = require("./CheckboxGroup/CheckboxGroup.cjs");
const CheckboxIndicator = require("./CheckboxIndicator/CheckboxIndicator.cjs");
const CheckIcon = require("./CheckIcon.cjs");
const Checkbox_module_css = require("./Checkbox.module.css.cjs");
const useId = require("../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-id/use-id.cjs");
const defaultProps = {
  labelPosition: "right",
  icon: CheckIcon.CheckboxIcon
};
const varsResolver = createVarsResolver.createVarsResolver(
  (theme, { radius, color, size, iconColor, variant, autoContrast }) => {
    const parsedColor = parseThemeColor.parseThemeColor({ color: color || theme.primaryColor, theme });
    const outlineColor = parsedColor.isThemeColor && parsedColor.shade === void 0 ? `var(--mantine-color-${parsedColor.color}-outline)` : parsedColor.color;
    return {
      root: {
        "--checkbox-size": getSize.getSize(size, "checkbox-size"),
        "--checkbox-radius": radius === void 0 ? void 0 : getSize.getRadius(radius),
        "--checkbox-color": variant === "outline" ? outlineColor : getThemeColor.getThemeColor(color, theme),
        "--checkbox-icon-color": iconColor ? getThemeColor.getThemeColor(iconColor, theme) : getAutoContrastValue.getAutoContrastValue(autoContrast, theme) ? getContrastColor.getContrastColor({ color, theme, autoContrast }) : void 0
      }
    };
  }
);
const Checkbox = factory.factory((_props, ref) => {
  const props = useProps.useProps("Checkbox", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    vars,
    color,
    label,
    id,
    size,
    radius,
    wrapperProps,
    checked,
    labelPosition,
    description,
    error,
    disabled,
    variant,
    indeterminate,
    icon,
    rootRef,
    iconColor,
    onChange,
    autoContrast,
    mod,
    ...others
  } = props;
  const ctx = CheckboxGroup_context.useCheckboxGroupContext();
  const _size = size || (ctx == null ? void 0 : ctx.size);
  const Icon = icon;
  const getStyles = useStyles.useStyles({
    name: "Checkbox",
    props,
    classes: Checkbox_module_css.default,
    className,
    style,
    classNames,
    styles,
    unstyled,
    vars,
    varsResolver
  });
  const { styleProps, rest } = extractStyleProps.extractStyleProps(others);
  const uuid = useId.useId(id);
  const contextProps = ctx ? {
    checked: ctx.value.includes(rest.value),
    onChange: (event) => {
      ctx.onChange(event);
      onChange == null ? void 0 : onChange(event);
    }
  } : {};
  return /* @__PURE__ */ jsxRuntime.jsx(
    InlineInput.InlineInput,
    {
      ...getStyles("root"),
      __staticSelector: "Checkbox",
      __stylesApiProps: props,
      id: uuid,
      size: _size,
      labelPosition,
      label,
      description,
      error,
      disabled,
      classNames,
      styles,
      unstyled,
      "data-checked": contextProps.checked || checked || void 0,
      variant,
      ref: rootRef,
      mod,
      ...styleProps,
      ...wrapperProps,
      children: /* @__PURE__ */ jsxRuntime.jsxs(Box.Box, { ...getStyles("inner"), mod: { "data-label-position": labelPosition }, children: [
        /* @__PURE__ */ jsxRuntime.jsx(
          Box.Box,
          {
            component: "input",
            id: uuid,
            ref,
            checked,
            disabled,
            mod: { error: !!error, indeterminate },
            ...getStyles("input", { focusable: true, variant }),
            onChange,
            ...rest,
            ...contextProps,
            type: "checkbox"
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx(Icon, { indeterminate, ...getStyles("icon") })
      ] })
    }
  );
});
Checkbox.classes = { ...Checkbox_module_css.default, ...InlineInput.InlineInputClasses };
Checkbox.displayName = "@mantine/core/Checkbox";
Checkbox.Group = CheckboxGroup.CheckboxGroup;
Checkbox.Indicator = CheckboxIndicator.CheckboxIndicator;
Checkbox.Card = CheckboxCard.CheckboxCard;
exports.Checkbox = Checkbox;
