"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 Popover = require("../Popover/Popover.cjs");
const Combobox_context = require("./Combobox.context.cjs");
const ComboboxChevron = require("./ComboboxChevron/ComboboxChevron.cjs");
const ComboboxClearButton = require("./ComboboxClearButton/ComboboxClearButton.cjs");
const ComboboxDropdown = require("./ComboboxDropdown/ComboboxDropdown.cjs");
const ComboboxDropdownTarget = require("./ComboboxDropdownTarget/ComboboxDropdownTarget.cjs");
const ComboboxEmpty = require("./ComboboxEmpty/ComboboxEmpty.cjs");
const ComboboxEventsTarget = require("./ComboboxEventsTarget/ComboboxEventsTarget.cjs");
const ComboboxFooter = require("./ComboboxFooter/ComboboxFooter.cjs");
const ComboboxGroup = require("./ComboboxGroup/ComboboxGroup.cjs");
const ComboboxHeader = require("./ComboboxHeader/ComboboxHeader.cjs");
const ComboboxHiddenInput = require("./ComboboxHiddenInput/ComboboxHiddenInput.cjs");
const ComboboxOption = require("./ComboboxOption/ComboboxOption.cjs");
const ComboboxOptions = require("./ComboboxOptions/ComboboxOptions.cjs");
const ComboboxSearch = require("./ComboboxSearch/ComboboxSearch.cjs");
const ComboboxTarget = require("./ComboboxTarget/ComboboxTarget.cjs");
const useCombobox = require("./use-combobox/use-combobox.cjs");
const Combobox_module_css = require("./Combobox.module.css.cjs");
const defaultProps = {
  keepMounted: true,
  withinPortal: true,
  resetSelectionOnOptionHover: false,
  width: "target",
  transitionProps: { transition: "fade", duration: 0 }
};
const varsResolver = createVarsResolver.createVarsResolver((_, { size, dropdownPadding }) => ({
  options: {
    "--combobox-option-fz": getSize.getFontSize(size),
    "--combobox-option-padding": getSize.getSize(size, "combobox-option-padding")
  },
  dropdown: {
    "--combobox-padding": dropdownPadding === void 0 ? void 0 : rem.rem(dropdownPadding),
    "--combobox-option-fz": getSize.getFontSize(size),
    "--combobox-option-padding": getSize.getSize(size, "combobox-option-padding")
  }
}));
function Combobox(_props) {
  const props = useProps.useProps("Combobox", defaultProps, _props);
  const {
    classNames,
    styles,
    unstyled,
    children,
    store: controlledStore,
    vars,
    onOptionSubmit,
    onClose,
    size,
    dropdownPadding,
    resetSelectionOnOptionHover,
    __staticSelector,
    readOnly,
    ...others
  } = props;
  const uncontrolledStore = useCombobox.useCombobox();
  const store = controlledStore || uncontrolledStore;
  const getStyles = useStyles.useStyles({
    name: __staticSelector || "Combobox",
    classes: Combobox_module_css.default,
    props,
    classNames,
    styles,
    unstyled,
    vars,
    varsResolver
  });
  const onDropdownClose = () => {
    onClose == null ? void 0 : onClose();
    store.closeDropdown();
  };
  return /* @__PURE__ */ jsxRuntime.jsx(
    Combobox_context.ComboboxProvider,
    {
      value: {
        getStyles,
        store,
        onOptionSubmit,
        size,
        resetSelectionOnOptionHover,
        readOnly
      },
      children: /* @__PURE__ */ jsxRuntime.jsx(
        Popover.Popover,
        {
          opened: store.dropdownOpened,
          ...others,
          onChange: (_opened) => !_opened && onDropdownClose(),
          withRoles: false,
          unstyled,
          children
        }
      )
    }
  );
}
const extendCombobox = (c) => c;
Combobox.extend = extendCombobox;
Combobox.classes = Combobox_module_css.default;
Combobox.displayName = "@mantine/core/Combobox";
Combobox.Target = ComboboxTarget.ComboboxTarget;
Combobox.Dropdown = ComboboxDropdown.ComboboxDropdown;
Combobox.Options = ComboboxOptions.ComboboxOptions;
Combobox.Option = ComboboxOption.ComboboxOption;
Combobox.Search = ComboboxSearch.ComboboxSearch;
Combobox.Empty = ComboboxEmpty.ComboboxEmpty;
Combobox.Chevron = ComboboxChevron.ComboboxChevron;
Combobox.Footer = ComboboxFooter.ComboboxFooter;
Combobox.Header = ComboboxHeader.ComboboxHeader;
Combobox.EventsTarget = ComboboxEventsTarget.ComboboxEventsTarget;
Combobox.DropdownTarget = ComboboxDropdownTarget.ComboboxDropdownTarget;
Combobox.Group = ComboboxGroup.ComboboxGroup;
Combobox.ClearButton = ComboboxClearButton.ComboboxClearButton;
Combobox.HiddenInput = ComboboxHiddenInput.ComboboxHiddenInput;
exports.Combobox = Combobox;
