"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const rem = require("../../core/utils/units-converters/rem.cjs");
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 extractStyleProps = require("../../core/Box/style-props/extract-style-props/extract-style-props.cjs");
const Box = require("../../core/Box/Box.cjs");
const polymorphicFactory = require("../../core/factory/polymorphic-factory.cjs");
const InputDescription = require("./InputDescription/InputDescription.cjs");
const InputError = require("./InputError/InputError.cjs");
const InputLabel = require("./InputLabel/InputLabel.cjs");
const InputPlaceholder = require("./InputPlaceholder/InputPlaceholder.cjs");
const InputWrapper_context = require("./InputWrapper.context.cjs");
const InputWrapper = require("./InputWrapper/InputWrapper.cjs");
const Input_module_css = require("./Input.module.css.cjs");
const defaultProps = {
  variant: "default",
  leftSectionPointerEvents: "none",
  rightSectionPointerEvents: "none",
  withAria: true,
  withErrorStyles: true
};
const varsResolver = createVarsResolver.createVarsResolver((_, props, ctx) => ({
  wrapper: {
    "--input-margin-top": ctx.offsetTop ? "calc(var(--mantine-spacing-xs) / 2)" : void 0,
    "--input-margin-bottom": ctx.offsetBottom ? "calc(var(--mantine-spacing-xs) / 2)" : void 0,
    "--input-height": getSize.getSize(props.size, "input-height"),
    "--input-fz": getSize.getFontSize(props.size),
    "--input-radius": props.radius === void 0 ? void 0 : getSize.getRadius(props.radius),
    "--input-left-section-width": props.leftSectionWidth !== void 0 ? rem.rem(props.leftSectionWidth) : void 0,
    "--input-right-section-width": props.rightSectionWidth !== void 0 ? rem.rem(props.rightSectionWidth) : void 0,
    "--input-padding-y": props.multiline ? getSize.getSize(props.size, "input-padding-y") : void 0,
    "--input-left-section-pointer-events": props.leftSectionPointerEvents,
    "--input-right-section-pointer-events": props.rightSectionPointerEvents
  }
}));
const Input = polymorphicFactory.polymorphicFactory((_props, ref) => {
  const props = useProps.useProps("Input", defaultProps, _props);
  const {
    classNames,
    className,
    style,
    styles,
    unstyled,
    required,
    __staticSelector,
    __stylesApiProps,
    size,
    wrapperProps,
    error,
    disabled,
    leftSection,
    leftSectionProps,
    leftSectionWidth,
    rightSection,
    rightSectionProps,
    rightSectionWidth,
    rightSectionPointerEvents,
    leftSectionPointerEvents,
    variant,
    vars,
    pointer,
    multiline,
    radius,
    id,
    withAria,
    withErrorStyles,
    mod,
    inputSize,
    ...others
  } = props;
  const { styleProps, rest } = extractStyleProps.extractStyleProps(others);
  const ctx = InputWrapper_context.useInputWrapperContext();
  const stylesCtx = { offsetBottom: ctx == null ? void 0 : ctx.offsetBottom, offsetTop: ctx == null ? void 0 : ctx.offsetTop };
  const getStyles = useStyles.useStyles({
    name: ["Input", __staticSelector],
    props: __stylesApiProps || props,
    classes: Input_module_css.default,
    className,
    style,
    classNames,
    styles,
    unstyled,
    stylesCtx,
    rootSelector: "wrapper",
    vars,
    varsResolver
  });
  const ariaAttributes = withAria ? {
    required,
    disabled,
    "aria-invalid": !!error,
    "aria-describedby": ctx == null ? void 0 : ctx.describedBy,
    id: (ctx == null ? void 0 : ctx.inputId) || id
  } : {};
  return /* @__PURE__ */ jsxRuntime.jsxs(
    Box.Box,
    {
      ...getStyles("wrapper"),
      ...styleProps,
      ...wrapperProps,
      mod: [
        {
          error: !!error && withErrorStyles,
          pointer,
          disabled,
          multiline,
          "data-with-right-section": !!rightSection,
          "data-with-left-section": !!leftSection
        },
        mod
      ],
      variant,
      size,
      children: [
        leftSection && /* @__PURE__ */ jsxRuntime.jsx(
          "div",
          {
            ...leftSectionProps,
            "data-position": "left",
            ...getStyles("section", {
              className: leftSectionProps == null ? void 0 : leftSectionProps.className,
              style: leftSectionProps == null ? void 0 : leftSectionProps.style
            }),
            children: leftSection
          }
        ),
        /* @__PURE__ */ jsxRuntime.jsx(
          Box.Box,
          {
            component: "input",
            ...rest,
            ...ariaAttributes,
            ref,
            required,
            mod: { disabled, error: !!error && withErrorStyles },
            variant,
            __size: inputSize,
            ...getStyles("input")
          }
        ),
        rightSection && /* @__PURE__ */ jsxRuntime.jsx(
          "div",
          {
            ...rightSectionProps,
            "data-position": "right",
            ...getStyles("section", {
              className: rightSectionProps == null ? void 0 : rightSectionProps.className,
              style: rightSectionProps == null ? void 0 : rightSectionProps.style
            }),
            children: rightSection
          }
        )
      ]
    }
  );
});
Input.classes = Input_module_css.default;
Input.Wrapper = InputWrapper.InputWrapper;
Input.Label = InputLabel.InputLabel;
Input.Error = InputError.InputError;
Input.Description = InputDescription.InputDescription;
Input.Placeholder = InputPlaceholder.InputPlaceholder;
Input.displayName = "@mantine/core/Input";
exports.Input = Input;
