import { jsxs as E, jsx as r } from "@emotion/react/jsx-runtime";
import { useState as R, useMemo as C } from "react";
import { renderAdornment as z } from "../subcomponents/RenderAdornment/RenderAdornment.js";
import { AUTOCOMPLETE_CLASSES as b } from "../constants.js";
import { ArrowRefreshSmOutlined as w, ArrowChevronSmDownOutlined as j } from "@m4l/icons";
import { AdormentsStyled as v, WrapperEndAdornmentStyled as x, CircularProgressStyled as L, IconButtonStyled as c } from "../slots/AutocompleteSlots.js";
function B(A) {
  const {
    loading: f,
    adjustedSize: n,
    ownerState: t,
    refresh: p,
    handleRefresh: h,
    disabled: l,
    onOpenLocal: S,
    open: g,
    readOnly: o,
    multiple: i,
    selectedValue: e,
    getOptionEndAdornment: d
  } = A, [y, a] = R(!1), O = () => {
    a(!0), h(), setTimeout(() => {
      a(!1);
    }, 600);
  }, m = C(() => {
    if (i || !e || Array.isArray(e) && e.length === 0)
      return null;
    const s = Array.isArray(e) ? e[0] : e, u = d?.(s);
    return u ? z(u, n) : null;
  }, [
    i,
    e,
    d,
    n
  ]);
  return /* @__PURE__ */ E(v, { ownerState: t, children: [
    !i && m && /* @__PURE__ */ r(x, { children: m }),
    f ? /* @__PURE__ */ r(
      L,
      {
        ownerState: t,
        size: n
      }
    ) : p ? /* @__PURE__ */ r(
      c,
      {
        ownerState: t,
        src: /* @__PURE__ */ r(w, {}),
        onClick: o ? void 0 : O,
        disabled: l || o,
        size: n,
        className: y ? b.refreshRotating : ""
      }
    ) : null,
    /* @__PURE__ */ r(
      c,
      {
        ownerState: t,
        icon: /* @__PURE__ */ r(j, {}),
        onClick: (s) => o ? void 0 : S(s),
        disabled: l || o,
        size: n,
        rotationAngle: g ? 180 : 0,
        "aria-label": "toggle Autocomplete"
      }
    )
  ] });
}
export {
  B as useEndAdornments
};
