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