'use strict';

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

var BaseSelect = require('../BaseSelect.js');
var index = require('../../_util/props-util/index.js');
var warning = require('../../vc-util/warning.js');
var commonUtil = require('./commonUtil.js');
var legacyUtil = require('./legacyUtil.js');

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);
  warning.warningOnce(
    mode !== "tags" || mergedOptions.every((opt) => !opt.disabled),
    "Please avoid setting option to disabled in tags mode since user can always type text as tag."
  );
  warning.warningOnce(
    mode !== "combobox" || !optionLabelProp,
    "`combobox` mode not support `optionLabelProp`. Please set `value` on Option directly."
  );
  warning.warningOnce(mode === "combobox" || !backfill, "`backfill` only works with `combobox` mode.");
  warning.warningOnce(
    mode === "combobox" || !getInputElement,
    "`getInputElement` only work with `combobox` mode."
  );
  warning.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")
    warning.warningOnce(false, "`onSearch` should work with `showSearch` instead of use alone.");
  warning.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);
    warning.warningOnce(
      !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`"
    );
    warning.warningOnce(
      !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 (!index.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 (!index.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) {
      warning.warningOnce(
        false,
        `\`children\` should be \`Select.Option\` or \`Select.OptGroup\` instead of \`${invalidateChildType.displayName || invalidateChildType.name || invalidateChildType}\`.`
      );
    }
    warning.warningOnce(
      inputValue === void 0,
      "`inputValue` is deprecated, please use `searchValue` instead."
    );
  }
}

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