import { jsx as W } from "@emotion/react/jsx-runtime";
import { useModuleSkeleton as G } from "@m4l/core";
import { useValuesAndHandlers as J } from "../useValuesAndHandlers.js";
import { useComponentSize as Q } from "../../../../../../hooks/useComponentSize/index.js";
import { useMemo as U, useCallback as j } from "react";
import { useMultipleChips as X } from "../useMultipleChips.js";
import { useEndAdornments as Y } from "../useEndAdornments.js";
import { renderOption as Z } from "../../subcomponents/renderOptions/index.js";
import { RenderInputStyled as $ } from "../../slots/AutocompleteSlots.js";
function de(m) {
  const {
    size: c,
    variant: a,
    disabled: t,
    multiple: o,
    error: i,
    readOnly: s,
    startAdornment: N,
    getOptionStartAdornment: h,
    getOptionEndAdornment: u,
    getOptionDescription: f,
    loading: V,
    refresh: D,
    placeholder: z,
    htmlFor: I
  } = m, {
    open: g,
    selectedValue: e,
    inputValue: E,
    isOptionEqualToValueLocal: p,
    handleDelete: y,
    handleRefresh: b,
    handleChange: M,
    handleInputChange: v,
    onCloseLocal: w,
    onOpenLocal: L,
    getOptionLabelLocal: d,
    checkKeyDown: x,
    scrollPositionOptionsRef: B
  } = J(m), { currentSize: r } = Q(c), _ = G(), k = !!m.startAdornment, R = !!(o && Array.isArray(e) && e.length > 0), l = U(() => ({
    size: r,
    variant: a,
    disabled: t,
    multiple: !!o,
    error: i,
    readOnly: s,
    startAdornment: k,
    hasChips: R
  }), [r, a, t, o, i, s, k, R]), A = X({
    selectedValue: e,
    multiple: o,
    adjustedSize: r,
    getOptionLabelLocal: d,
    ownerState: l,
    handleDelete: y,
    disabled: t,
    startAdornment: N,
    getOptionStartAdornment: h,
    getOptionEndAdornment: u,
    getOptionDescription: f
  }), C = Y({
    loading: V,
    adjustedSize: r,
    ownerState: l,
    refresh: D,
    handleRefresh: b,
    disabled: t,
    onOpenLocal: L,
    open: g,
    readOnly: s,
    multiple: o,
    selectedValue: e,
    getOptionEndAdornment: u
  }), q = j((S, n) => {
    const O = o ? Array.isArray(e) && e.some((P) => p(n, P)) : p(n, e);
    return Z(S, {
      ...typeof n == "object" && n !== null ? n : {},
      label: d(n),
      selected: O,
      disabled: t,
      size: c
    }, h, u, f);
  }, [
    o,
    e,
    p,
    d,
    t,
    c,
    h,
    u,
    f
  ]), F = j((S) => {
    const { InputLabelProps: n, inputProps: O, InputProps: P, ...H } = S, { className: ee, ...K } = P, { className: te, ...T } = O;
    return /* @__PURE__ */ W(
      $,
      {
        variant: a,
        ownerState: l,
        InputLabelProps: {
          ...n,
          shrink: !0
        },
        inputProps: { ...T, id: I },
        error: i,
        ...H,
        autoComplete: "off",
        InputProps: {
          ...K,
          startAdornment: A,
          endAdornment: C,
          readOnly: s
        },
        SelectProps: { native: !0 },
        size: r,
        fullWidth: !0,
        disabled: t,
        placeholder: z
      }
    );
  }, [
    a,
    l,
    I,
    i,
    A,
    C,
    s,
    r,
    t,
    z
  ]);
  return {
    // propiedades de useAutocomplete
    ownerState: l,
    isSkeleton: _,
    currentSize: r,
    memoizedRenderOption: q,
    memoizedRenderInput: F,
    // propiedades de useValuesAndHandlers
    open: g,
    selectedValue: e,
    inputValue: E,
    isOptionEqualToValueLocal: p,
    handleDelete: y,
    handleRefresh: b,
    handleChange: M,
    handleInputChange: v,
    onCloseLocal: w,
    onOpenLocal: L,
    getOptionLabelLocal: d,
    checkKeyDown: x,
    scrollPositionOptionsRef: B,
    // propiedades de useMultipleChips
    multipleChips: A,
    // propiedades de useEndAdornments
    endAdornments: C
  };
}
export {
  de as useAutocomplete
};
