'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

require('../../../../utils/index.cjs');
var BaseSelect = require('../BaseSelect.cjs');
var commonUtil = require('./commonUtil.cjs');
var legacyUtil = require('./legacyUtil.cjs');
var log = require('../../../../utils/log.cjs');
var is = require('../../../../utils/is.cjs');

function warningProps(props) {
  const {
    mode,
    options,
    children,
    backfill,
    allowClear,
    placeholder,
    getInputElement,
    showSearch,
    onSearch,
    defaultOpen,
    autofocus,
    labelInValue,
    value,
    inputValue,
    optionLabelProp
  } = props;
  const multiple = BaseSelect.isMultiple(mode);
  const mergedShowSearch = showSearch !== void 0 ? showSearch : multiple || mode === "combobox";
  const mergedOptions = options || legacyUtil.convertChildrenToData(children);
  log.warning(
    mode !== "tags" || mergedOptions.every((opt) => !opt.disabled),
    "Please avoid setting option to disabled in tags mode since user can always type text as tag."
  );
  log.warning(
    mode !== "combobox" || !optionLabelProp,
    "`combobox` mode not support `optionLabelProp`. Please set `value` on Option directly."
  );
  log.warning(mode === "combobox" || !backfill, "`backfill` only works with `combobox` mode.");
  log.warning(
    mode === "combobox" || !getInputElement,
    "`getInputElement` only work with `combobox` mode."
  );
  log.noteOnce(
    mode !== "combobox" || !getInputElement || !allowClear || !placeholder,
    "Customize `getInputElement` should customize clear and placeholder logic instead of configuring `allowClear` and `placeholder`."
  );
  if (onSearch && !mergedShowSearch && mode !== "combobox" && mode !== "tags")
    log.warning(false, "`onSearch` should work with `showSearch` instead of use alone.");
  log.noteOnce(
    !defaultOpen || autofocus,
    "`defaultOpen` makes Select open without focus which means it will not close by click outside. You can set `autofocus` if needed."
  );
  if (value !== void 0 && value !== null) {
    const values = commonUtil.toArray(value);
    log.warning(
      !labelInValue || values.every((val) => typeof val === "object" && ("key" in val || "value" in val)),
      "`value` should in shape of `{ value: string | number, label?: any }` when you set `labelInValue` to `true`"
    );
    log.warning(
      !multiple || Array.isArray(value),
      "`value` should be array when `mode` is `multiple` or `tags`"
    );
  }
  if (children) {
    let invalidateChildType = null;
    children.some((node) => {
      var _a;
      if (!is.isValidElement(node) || !node.type)
        return false;
      const { type } = node;
      if (type.isSelectOption)
        return false;
      if (type.isSelectOptGroup) {
        const childs = ((_a = node.children) == null ? void 0 : _a.default()) || [];
        const allChildrenValid = childs.every((subNode) => {
          if (!is.isValidElement(subNode) || !node.type || subNode.type.isSelectOption)
            return true;
          invalidateChildType = subNode.type;
          return false;
        });
        if (allChildrenValid)
          return false;
        return true;
      }
      invalidateChildType = type;
      return true;
    });
    if (invalidateChildType) {
      log.warning(
        false,
        `\`children\` should be \`Select.Option\` or \`Select.OptGroup\` instead of \`${invalidateChildType.displayName || invalidateChildType.name || invalidateChildType}\`.`
      );
    }
    log.warning(
      inputValue === void 0,
      "`inputValue` is deprecated, please use `searchValue` instead."
    );
  }
}

exports.default = warningProps;
//# sourceMappingURL=warningPropsUtil.cjs.map
