'use client'; import { ComponentType, ReactNode, useEffect, useMemo, useState } from 'react'; import Select, { OptionProps, GroupBase, InputActionMeta, MultiValue, SingleValue, components as ReactSelectComponents, ControlProps, MenuListProps, } from 'react-select'; import CreatableSelect from 'react-select/creatable'; import makeAnimated from 'react-select/animated'; import { useDebounce } from 'use-debounce'; import { cn, getByPath } from '@/lib/helper'; import useSWRInfinite from 'swr/infinite'; import { httpClientFetcher } from '@/services/http/client'; import { BaseApiResponse, ErrorApiResponse, SuccessApiResponse, } from '@/types/api/api-general'; import { isResponseError, isResponseSuccess } from '@/lib/api-helper'; export interface OptionType { value: T; label: string; className?: string; labelClassName?: string; } export type OptionComponent = ComponentType< OptionProps> >; interface SelectInputBaseProps { label?: ReactNode; bottomLabel?: ReactNode; options: T[]; optionComponent?: OptionComponent; components?: Partial; isDisabled?: boolean; readOnly?: boolean; isLoading?: boolean; isClearable?: boolean; isRtl?: boolean; isSearchable?: boolean; isMulti?: boolean; placeholder?: string; required?: boolean; className?: { wrapper?: string; label?: string; select?: string; inputPrefix?: string; inputSuffix?: string; inputPrefixSuffixWrapper?: string; }; isError?: boolean; errorMessage?: string; isAnimated?: boolean; openMenu?: boolean; delay?: number; onInputChange?: (search: string) => void; startAdornment?: ReactNode; inputPrefix?: ReactNode; inputSuffix?: ReactNode; menuPortalTarget?: HTMLElement | null; closeMenuOnSelect?: boolean; hideSelectedOptions?: boolean; onMenuScrollToBottom?: ((event: WheelEvent | TouchEvent) => void) | undefined; } export interface SelectInputProps extends SelectInputBaseProps { createables?: boolean; value?: T | T[] | null; onChange?: (val: T | T[] | null) => void; } const animatedComponents = makeAnimated(); const CustomControl = < Option, IsMulti extends boolean, Group extends GroupBase