"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 useProps = require("../../core/MantineProvider/use-props/use-props.cjs");
const useStyles = require("../../core/styles-api/use-styles/use-styles.cjs");
const Box = require("../../core/Box/Box.cjs");
const factory = require("../../core/factory/factory.cjs");
const CloseButton = require("../CloseButton/CloseButton.cjs");
const PillsInput_context = require("../PillsInput/PillsInput.context.cjs");
const PillGroup_context = require("./PillGroup.context.cjs");
const PillGroup = require("./PillGroup/PillGroup.cjs");
const Pill_module_css = require("./Pill.module.css.cjs");
const defaultProps = {
  variant: "default"
};
const varsResolver = createVarsResolver.createVarsResolver((_, { radius }, { size }) => ({
  root: {
    "--pill-fz": getSize.getSize(size, "pill-fz"),
    "--pill-height": getSize.getSize(size, "pill-height"),
    "--pill-radius": radius === void 0 ? void 0 : getSize.getRadius(radius)
  }
}));
const Pill = factory.factory((_props, ref) => {
  const props = useProps.useProps("Pill", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    vars,
    variant,
    children,
    withRemoveButton,
    onRemove,
    removeButtonProps,
    radius,
    size,
    disabled,
    mod,
    ...others
  } = props;
  const ctx = PillGroup_context.usePillGroupContext();
  const pillsInputCtx = PillsInput_context.usePillsInputContext();
  const _size = size || (ctx == null ? void 0 : ctx.size) || void 0;
  const _variant = (pillsInputCtx == null ? void 0 : pillsInputCtx.variant) === "filled" ? "contrast" : variant || "default";
  const getStyles = useStyles.useStyles({
    name: "Pill",
    classes: Pill_module_css.default,
    props,
    className,
    style,
    classNames,
    styles,
    unstyled,
    vars,
    varsResolver,
    stylesCtx: { size: _size }
  });
  return /* @__PURE__ */ jsxRuntime.jsxs(
    Box.Box,
    {
      component: "span",
      ref,
      variant: _variant,
      size: _size,
      ...getStyles("root", { variant: _variant }),
      mod: [
        { "with-remove": withRemoveButton && !disabled, disabled: disabled || (ctx == null ? void 0 : ctx.disabled) },
        mod
      ],
      ...others,
      children: [
        /* @__PURE__ */ jsxRuntime.jsx("span", { ...getStyles("label"), children }),
        withRemoveButton && /* @__PURE__ */ jsxRuntime.jsx(
          CloseButton.CloseButton,
          {
            variant: "transparent",
            radius,
            tabIndex: -1,
            "aria-hidden": true,
            unstyled,
            ...removeButtonProps,
            ...getStyles("remove", {
              className: removeButtonProps == null ? void 0 : removeButtonProps.className,
              style: removeButtonProps == null ? void 0 : removeButtonProps.style
            }),
            onMouseDown: (event) => {
              var _a;
              event.preventDefault();
              event.stopPropagation();
              (_a = removeButtonProps == null ? void 0 : removeButtonProps.onMouseDown) == null ? void 0 : _a.call(removeButtonProps, event);
            },
            onClick: (event) => {
              var _a;
              event.stopPropagation();
              onRemove == null ? void 0 : onRemove();
              (_a = removeButtonProps == null ? void 0 : removeButtonProps.onClick) == null ? void 0 : _a.call(removeButtonProps, event);
            }
          }
        )
      ]
    }
  );
});
Pill.classes = Pill_module_css.default;
Pill.displayName = "@mantine/core/Pill";
Pill.Group = PillGroup.PillGroup;
exports.Pill = Pill;
