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