'use strict';

var chunkFDRFBFI7_cjs = require('./chunk-FDRFBFI7.cjs');
var React4 = require('react');
var icons = require('@blueprintjs/icons');
var select = require('@base-ui/react/select');
var classnames = require('classnames');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React4__namespace = /*#__PURE__*/_interopNamespace(React4);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var typedReactMemo = React4__namespace.default.memo;
function useEventCallback(callback) {
  const latestCallbackValueWrapper = React4__namespace.useRef((...args) => {
    if (typeof globalThis.console !== "undefined") {
      globalThis.console.error("A callback created with `useEventCallback` was called during the initial render of a component. This will throw an error in the future.");
    }
    return callback(...args);
  });
  React4__namespace.useEffect(() => {
    latestCallbackValueWrapper.current = callback;
  }, [callback]);
  return React4__namespace.useCallback((...args) => latestCallbackValueWrapper.current(...args), []);
}

// src/base-components/select/Select.module.css
var Select_default = {};

// src/base-components/select/Select.tsx
function _extends() {
  return _extends = Object.assign ? Object.assign.bind() : function(n) {
    for (var e = 1; e < arguments.length; e++) {
      var t = arguments[e];
      for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
    }
    return n;
  }, _extends.apply(null, arguments);
}
function SelectRoot({
  children,
  ...rest
}) {
  return /* @__PURE__ */ React4__namespace.default.createElement(select.Select.Root, rest, children);
}
function SelectTrigger({
  className,
  placeholder,
  children,
  ...rest
}) {
  return /* @__PURE__ */ React4__namespace.default.createElement(select.Select.Trigger, _extends({
    className: classnames__default.default(Select_default.osdkSelectTrigger, className)
  }, rest), children ?? /* @__PURE__ */ React4__namespace.default.createElement(React4__namespace.default.Fragment, null, /* @__PURE__ */ React4__namespace.default.createElement("div", {
    className: Select_default.osdkSelectValueContainer
  }, /* @__PURE__ */ React4__namespace.default.createElement(select.Select.Value, {
    className: Select_default.osdkSelectValue
  }), placeholder != null && /* @__PURE__ */ React4__namespace.default.createElement("span", {
    className: Select_default.osdkSelectPlaceholder
  }, placeholder)), /* @__PURE__ */ React4__namespace.default.createElement(select.Select.Icon, {
    className: Select_default.osdkSelectIcon
  }, /* @__PURE__ */ React4__namespace.default.createElement(icons.CaretDown, null))));
}
function SelectValue(props) {
  const {
    className,
    ...rest
  } = props;
  return /* @__PURE__ */ React4__namespace.default.createElement(select.Select.Value, _extends({
    className: classnames__default.default(Select_default.osdkSelectValue, className)
  }, rest));
}
function SelectPositioner({
  className,
  children,
  ...rest
}) {
  return /* @__PURE__ */ React4__namespace.default.createElement(select.Select.Positioner, _extends({
    className: classnames__default.default(Select_default.osdkSelectPositioner, className),
    sideOffset: 4,
    alignItemWithTrigger: false
  }, rest), children);
}
function SelectPopup({
  className,
  children,
  ...rest
}) {
  return /* @__PURE__ */ React4__namespace.default.createElement(select.Select.Popup, _extends({
    className: classnames__default.default(Select_default.osdkSelectPopup, className)
  }, rest), children);
}
function SelectItem({
  className,
  children,
  ...rest
}) {
  return /* @__PURE__ */ React4__namespace.default.createElement(select.Select.Item, _extends({
    className: classnames__default.default(Select_default.osdkSelectItem, className)
  }, rest), /* @__PURE__ */ React4__namespace.default.createElement(select.Select.ItemText, null, children));
}
var Select = {
  Root: SelectRoot,
  Trigger: SelectTrigger,
  Value: SelectValue,
  Portal: select.Select.Portal,
  Positioner: SelectPositioner,
  Popup: SelectPopup,
  Item: SelectItem
};

// src/action-form/fields/DropdownField.module.css
var DropdownField_default = {};

// src/action-form/fields/DropdownField.tsx
function _extends2() {
  return _extends2 = Object.assign ? Object.assign.bind() : function(n) {
    for (var e = 1; e < arguments.length; e++) {
      var t = arguments[e];
      for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
    }
    return n;
  }, _extends2.apply(null, arguments);
}
var EMPTY_ARRAY = [];
var DropdownField = typedReactMemo(function DropdownFieldFn({
  isSearchable = false,
  isMultiple,
  itemToStringLabel,
  renderItemLabel,
  itemToKey,
  value,
  query,
  onQueryChange,
  disableClientSideFiltering,
  popupStatus,
  trailingItem,
  modal = true,
  ...rest
}) {
  const normalizedValue = value ?? (isMultiple ? EMPTY_ARRAY : null);
  const resolvedItemToStringLabel = itemToStringLabel ?? defaultItemToStringLabel;
  const resolvedRenderItemLabel = renderItemLabel ?? resolvedItemToStringLabel;
  const getKey = React4.useCallback((item) => itemToKey?.(item) ?? resolvedItemToStringLabel(item), [itemToKey, resolvedItemToStringLabel]);
  if (isSearchable || isMultiple) {
    return /* @__PURE__ */ React4__namespace.default.createElement(ComboboxDropdown, _extends2({}, rest, {
      isMultiple,
      value: normalizedValue,
      itemToStringLabel: resolvedItemToStringLabel,
      renderItemLabel: resolvedRenderItemLabel,
      getKey,
      isSearchable,
      query,
      onQueryChange,
      disableClientSideFiltering,
      popupStatus,
      trailingItem,
      modal
    }));
  }
  return /* @__PURE__ */ React4__namespace.default.createElement(SelectDropdown, _extends2({}, rest, {
    value: normalizedValue,
    itemToStringLabel: resolvedItemToStringLabel,
    renderItemLabel: resolvedRenderItemLabel,
    getKey,
    modal
  }));
});
var SelectDropdown = typedReactMemo(function SelectDropdownFn({
  id,
  value,
  onChange,
  items,
  itemToStringLabel,
  renderItemLabel,
  getKey,
  isItemEqual,
  placeholder,
  portalRef,
  portalContainer,
  onBlur,
  modal = true,
  disabled
}) {
  const [open, setOpen] = React4.useState(false);
  const isOpen = !disabled && open;
  const hasValue = value != null;
  const renderSingleSelectedItemLabel = React4.useCallback((selectedValue) => selectedValue == null ? null : renderItemLabel(selectedValue), [renderItemLabel]);
  const handleOpenChange = React4.useCallback((nextOpen) => {
    if (disabled) {
      return;
    }
    setOpen(nextOpen);
    if (!nextOpen) {
      onBlur?.();
    }
  }, [disabled, onBlur]);
  const handleClear = React4.useCallback(() => {
    onChange?.(null);
    handleOpenChange(false);
  }, [onChange, handleOpenChange]);
  const handleDismiss = React4.useCallback(() => {
    handleOpenChange(false);
  }, [handleOpenChange]);
  return /* @__PURE__ */ React4__namespace.default.createElement("div", null, /* @__PURE__ */ React4__namespace.default.createElement(Select.Root, {
    value,
    onValueChange: onChange,
    open: isOpen,
    onOpenChange: handleOpenChange,
    isItemEqualToValue: isItemEqual,
    itemToStringLabel,
    modal,
    disabled
  }, /* @__PURE__ */ React4__namespace.default.createElement(Select.Trigger, {
    id,
    placeholder,
    disabled
  }, /* @__PURE__ */ React4__namespace.default.createElement("div", {
    className: Select_default.osdkSelectValueContainer
  }, /* @__PURE__ */ React4__namespace.default.createElement(Select.Value, null, renderSingleSelectedItemLabel), placeholder != null && /* @__PURE__ */ React4__namespace.default.createElement("span", {
    className: Select_default.osdkSelectPlaceholder
  }, placeholder)), hasValue && /* @__PURE__ */ React4__namespace.default.createElement("span", {
    role: "button",
    "aria-label": "Clear",
    className: Select_default.osdkSelectClear,
    "aria-disabled": disabled || void 0,
    onMouseDown: disabled ? void 0 : preventTriggerOpen,
    onClick: disabled ? void 0 : handleClear
  }, /* @__PURE__ */ React4__namespace.default.createElement(icons.SmallCross, null)), /* @__PURE__ */ React4__namespace.default.createElement("span", {
    className: Select_default.osdkSelectIcon
  }, /* @__PURE__ */ React4__namespace.default.createElement(icons.CaretDown, null))), /* @__PURE__ */ React4__namespace.default.createElement(Select.Portal, {
    ref: portalRef,
    container: portalContainer
  }, isOpen && modal && /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.PortalDismissLayer, {
    className: DropdownField_default.osdkSelectDismissLayer,
    onDismiss: handleDismiss
  }), /* @__PURE__ */ React4__namespace.default.createElement(Select.Positioner, null, /* @__PURE__ */ React4__namespace.default.createElement(Select.Popup, null, items.map((item) => {
    const itemLabel = itemToStringLabel(item);
    return /* @__PURE__ */ React4__namespace.default.createElement(Select.Item, {
      key: getKey(item),
      value: item,
      label: itemLabel,
      "aria-label": itemLabel
    }, renderItemLabel(item));
  }))))));
});
var ComboboxDropdown = typedReactMemo(function ComboboxDropdownFn({
  id,
  value,
  onChange,
  items,
  itemToStringLabel,
  renderItemLabel,
  getKey,
  isItemEqual,
  isMultiple,
  isSearchable,
  placeholder,
  portalRef,
  portalContainer,
  query,
  onQueryChange,
  disableClientSideFiltering,
  popupStatus,
  trailingItem,
  onBlur,
  modal = true,
  disabled
}) {
  const [open, setOpen] = React4.useState(false);
  const isOpen = !disabled && open;
  const hasValue = isMultiple ? Array.isArray(value) && value.length > 0 : value != null;
  const renderSingleSelectedItemLabel = React4.useCallback((selectedValue) => selectedValue == null ? null : renderItemLabel(selectedValue), [renderItemLabel]);
  const handleOpenChange = React4.useCallback((nextOpen) => {
    setOpen(nextOpen);
    if (!nextOpen) {
      onBlur?.();
    }
  }, [onBlur]);
  const handleValueChange = React4.useCallback((...args) => {
    onChange?.(...args);
    if (isMultiple) {
      onBlur?.();
    }
  }, [onChange, onBlur, isMultiple]);
  const handleClear = React4.useCallback(() => {
    const cleared = isMultiple ? EMPTY_ARRAY : null;
    handleValueChange(cleared);
    if (!isMultiple) {
      handleOpenChange(false);
    }
  }, [isMultiple, handleValueChange, handleOpenChange]);
  const handleRemoveItem = React4.useCallback((itemToRemove) => {
    if (!isMultiple || !Array.isArray(value)) {
      return;
    }
    const next = value.filter((v) => isItemEqual != null ? !isItemEqual(v, itemToRemove) : v !== itemToRemove);
    handleValueChange(next);
  }, [isMultiple, value, handleValueChange, isItemEqual]);
  const handleDismiss = React4.useCallback(() => {
    handleOpenChange(false);
  }, [handleOpenChange]);
  const renderItem = React4.useCallback((item) => {
    const itemLabel = itemToStringLabel(item);
    return /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Item, {
      key: getKey(item),
      value: item,
      "aria-label": itemLabel
    }, isMultiple && /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.ItemIndicator, null, /* @__PURE__ */ React4__namespace.default.createElement(icons.Tick, null)), renderItemLabel(item));
  }, [getKey, isMultiple, itemToStringLabel, renderItemLabel]);
  return /* @__PURE__ */ React4__namespace.default.createElement("div", null, /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Root, {
    value,
    onValueChange: handleValueChange,
    open: isOpen,
    onOpenChange: handleOpenChange,
    multiple: isMultiple,
    itemToStringLabel,
    isItemEqualToValue: isItemEqual,
    items,
    inputValue: query,
    onInputValueChange: onQueryChange,
    filter: disableClientSideFiltering ? null : void 0,
    disabled
  }, /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Trigger, {
    id,
    disabled,
    className: isMultiple ? chunkFDRFBFI7_cjs.Combobox_default.osdkComboboxTriggerMulti : void 0
  }, /* @__PURE__ */ React4__namespace.default.createElement("div", {
    className: chunkFDRFBFI7_cjs.Combobox_default.osdkComboboxValueContainer
  }, isMultiple && Array.isArray(value) && value.length > 0 ? /* @__PURE__ */ React4__namespace.default.createElement("div", {
    className: chunkFDRFBFI7_cjs.Combobox_default.osdkComboboxTriggerChips
  }, value.map((item) => /* @__PURE__ */ React4__namespace.default.createElement("span", {
    key: getKey(item),
    className: chunkFDRFBFI7_cjs.Combobox_default.osdkComboboxTriggerChip
  }, renderItemLabel(item), /* @__PURE__ */ React4__namespace.default.createElement("span", {
    role: "button",
    "aria-label": `Remove ${itemToStringLabel(item)}`,
    className: chunkFDRFBFI7_cjs.Combobox_default.osdkComboboxTriggerChipRemove,
    "aria-disabled": disabled || void 0,
    onMouseDown: disabled ? void 0 : preventTriggerOpen,
    onClick: disabled ? void 0 : () => handleRemoveItem(item)
  }, /* @__PURE__ */ React4__namespace.default.createElement(icons.Cross, {
    size: 12
  }))))) : /* @__PURE__ */ React4__namespace.default.createElement(React4__namespace.default.Fragment, null, /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Value, null, renderSingleSelectedItemLabel), !hasValue && placeholder != null && /* @__PURE__ */ React4__namespace.default.createElement("span", {
    className: chunkFDRFBFI7_cjs.Combobox_default.osdkComboboxPlaceholder
  }, placeholder))), hasValue && /* @__PURE__ */ React4__namespace.default.createElement("span", {
    role: "button",
    "aria-label": "Clear",
    className: chunkFDRFBFI7_cjs.Combobox_default.osdkComboboxClear,
    "aria-disabled": disabled || void 0,
    onMouseDown: disabled ? void 0 : preventTriggerOpen,
    onClick: disabled ? void 0 : handleClear
  }, /* @__PURE__ */ React4__namespace.default.createElement(icons.SmallCross, null)), /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Icon, null, /* @__PURE__ */ React4__namespace.default.createElement(icons.CaretDown, null))), /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Portal, {
    ref: portalRef,
    container: portalContainer
  }, isOpen && modal && /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.PortalDismissLayer, {
    className: DropdownField_default.osdkComboboxDismissLayer,
    onDismiss: handleDismiss
  }), /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Positioner, null, /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Popup, null, isSearchable && /* @__PURE__ */ React4__namespace.default.createElement("div", {
    className: chunkFDRFBFI7_cjs.Combobox_default.osdkComboboxPopupSearchInput
  }, /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.SearchInput, {
    placeholder: "Search\u2026"
  })), popupStatus, popupStatus == null && /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Empty, null, "No results"), /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.List, null, /* @__PURE__ */ React4__namespace.default.createElement(chunkFDRFBFI7_cjs.Combobox.Collection, null, renderItem), trailingItem))))));
});
function preventTriggerOpen(e) {
  e.stopPropagation();
  e.preventDefault();
}
function defaultItemToStringLabel(item) {
  if (item == null || typeof item !== "object") {
    return String(item);
  }
  if ("label" in item && item.label != null && typeof item.label === "string") {
    return item.label;
  }
  return String(item);
}

exports.DropdownField = DropdownField;
exports.typedReactMemo = typedReactMemo;
exports.useEventCallback = useEventCallback;
//# sourceMappingURL=chunk-ASBETQHB.cjs.map
//# sourceMappingURL=chunk-ASBETQHB.cjs.map