import Be from "../../@babel/runtime/helpers/esm/extends.mjs";
import X from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import Y from "../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import s from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import Fe from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import "../../rc-select/es/Select.mjs";
import "../../rc-select/es/Option.mjs";
import "../../rc-select/es/OptGroup.mjs";
import Je from "../../rc-select/es/BaseSelect.mjs";
import * as i from "react";
import qe from "../../rc-select/es/hooks/useId.mjs";
import Z from "../../rc-util/es/hooks/useEvent.mjs";
import ee from "../../rc-util/es/hooks/useMergedState.mjs";
import ze from "./context.mjs";
import Ge from "./hooks/useDisplayValues.mjs";
import Qe from "./hooks/useMissingValues.mjs";
import Ue from "./hooks/useOptions.mjs";
import Xe from "./hooks/useSearchConfig.mjs";
import Ye from "./hooks/useSearchOptions.mjs";
import Ze from "./hooks/useSelect.mjs";
import ea from "./hooks/useValues.mjs";
import aa from "./OptionList/index.mjs";
import oa from "./Panel.mjs";
import { SHOW_PARENT as oe, SHOW_CHILD as na, toRawValues as ae, fillFieldNames as ra, toPathKeys as ta } from "./utils/commonUtil.mjs";
import { formatStrategyValues as la, toPathOptions as ia } from "./utils/treeUtil.mjs";
import da, { warningNullOptions as sa } from "./utils/warningPropsUtil.mjs";
var ua = ["id", "prefixCls", "fieldNames", "defaultValue", "value", "changeOnSelect", "onChange", "displayRender", "checkable", "autoClearSearchValue", "searchValue", "onSearch", "showSearch", "expandTrigger", "options", "dropdownPrefixCls", "loadData", "popupVisible", "open", "popupClassName", "dropdownClassName", "dropdownMenuColumnStyle", "dropdownStyle", "popupPlacement", "placement", "onDropdownVisibleChange", "onPopupVisibleChange", "expandIcon", "loadingIcon", "children", "dropdownMatchSelectWidth", "showCheckedStrategy"], m = /* @__PURE__ */ i.forwardRef(function(e, ne) {
  var re = e.id, I = e.prefixCls, b = I === void 0 ? "rc-cascader" : I, M = e.fieldNames, te = e.defaultValue, le = e.value, h = e.changeOnSelect, x = e.onChange, ie = e.displayRender, f = e.checkable, k = e.autoClearSearchValue, E = k === void 0 ? !0 : k, de = e.searchValue, W = e.onSearch, se = e.showSearch, R = e.expandTrigger, ue = e.options, g = e.dropdownPrefixCls, H = e.loadData, ce = e.popupVisible, T = e.open, pe = e.popupClassName, me = e.dropdownClassName, K = e.dropdownMenuColumnStyle, he = e.dropdownStyle, fe = e.popupPlacement, ge = e.placement, S = e.onDropdownVisibleChange, C = e.onPopupVisibleChange, $ = e.expandIcon, A = $ === void 0 ? ">" : $, L = e.loadingIcon, Se = e.children, j = e.dropdownMatchSelectWidth, Ce = j === void 0 ? !1 : j, B = e.showCheckedStrategy, v = B === void 0 ? oe : B, ve = Fe(e, ua), we = qe(re), t = !!f, Ve = ee(te, {
    value: le,
    postState: ae
  }), F = s(Ve, 2), ye = F[0], _e = F[1], n = i.useMemo(
    function() {
      return ra(M);
    },
    /* eslint-disable react-hooks/exhaustive-deps */
    [JSON.stringify(M)]
    /* eslint-enable react-hooks/exhaustive-deps */
  ), Oe = Ue(n, ue), w = s(Oe, 3), r = w[0], u = w[1], c = w[2], Ne = ee("", {
    value: de,
    postState: function(a) {
      return a || "";
    }
  }), J = s(Ne, 2), p = J[0], q = J[1], Pe = function(a, l) {
    q(a), l.source !== "blur" && W && W(a);
  }, De = Xe(se), z = s(De, 2), Ie = z[0], G = z[1], V = Ye(p, r, n, g || b, G, h), be = Qe(r, n), Me = ea(t, ye, u, c, be), y = s(Me, 3), d = y[0], _ = y[1], O = y[2], xe = i.useMemo(function() {
    var o = ta(d), a = la(o, u, v);
    return [].concat(Y(O), Y(c(a)));
  }, [d, u, c, O, v]), ke = Ge(xe, r, n, t, ie), Q = Z(function(o) {
    if (_e(o), x) {
      var a = ae(o), l = a.map(function(Le) {
        return ia(Le, r, n).map(function(je) {
          return je.option;
        });
      }), P = t ? a : a[0], D = t ? l : l[0];
      x(P, D);
    }
  }), Ee = Ze(t, Q, d, _, O, u, c, v), N = Z(function(o) {
    (!t || E) && q(""), Ee(o);
  }), We = function(a, l) {
    if (l.type === "clear") {
      Q([]);
      return;
    }
    var P = l.values[0], D = P.valueCells;
    N(D);
  }, Re = T !== void 0 ? T : ce, He = me || pe, Te = ge || fe, Ke = function(a) {
    S == null || S(a), C == null || C(a);
  };
  process.env.NODE_ENV !== "production" && (da(e), sa(r, n));
  var $e = i.useMemo(function() {
    return {
      options: r,
      fieldNames: n,
      values: d,
      halfValues: _,
      changeOnSelect: h,
      onSelect: N,
      checkable: f,
      searchOptions: V,
      dropdownPrefixCls: g,
      loadData: H,
      expandTrigger: R,
      expandIcon: A,
      loadingIcon: L,
      dropdownMenuColumnStyle: K
    };
  }, [r, n, d, _, h, N, f, V, g, H, R, A, L, K]), U = !(p ? V : r).length, Ae = (
    // Search to match width
    p && G.matchInputWidth || // Empty keep the width
    U ? {} : {
      minWidth: "auto"
    }
  );
  return /* @__PURE__ */ i.createElement(ze.Provider, {
    value: $e
  }, /* @__PURE__ */ i.createElement(Je, Be({}, ve, {
    // MISC
    ref: ne,
    id: we,
    prefixCls: b,
    autoClearSearchValue: E,
    dropdownMatchSelectWidth: Ce,
    dropdownStyle: X(X({}, Ae), he),
    displayValues: ke,
    onDisplayValuesChange: We,
    mode: t ? "multiple" : void 0,
    searchValue: p,
    onSearch: Pe,
    showSearch: Ie,
    OptionList: aa,
    emptyOptions: U,
    open: Re,
    dropdownClassName: He,
    placement: Te,
    onDropdownVisibleChange: Ke,
    getRawInputElement: function() {
      return Se;
    }
  })));
});
process.env.NODE_ENV !== "production" && (m.displayName = "Cascader");
m.SHOW_PARENT = oe;
m.SHOW_CHILD = na;
m.Panel = oa;
export {
  m as default
};
